Add simple support for receiving HTML mails

Create a plain text document by removing all HTML tags with Nokogiri.
This commit is contained in:
Patrick Gansterer 2017-09-30 01:18:02 +02:00
parent 7d594bf391
commit ecdf3bc147

View file

@ -19,7 +19,10 @@ class MessagesMailReceiver
mail_part = nil
if mail.multipart?
for part in mail.parts
mail_part = part if MIME::Type.simplified(part.content_type) == "text/plain"
content_type = MIME::Type.simplified(part.content_type)
if content_type == "text/plain" || !mail_part && content_type == "text/html"
mail_part = part
end
end
else
mail_part = mail
@ -30,6 +33,10 @@ class MessagesMailReceiver
body = body.force_encoding mail_part.content_type_parameters[:charset]
end
if MIME::Type.simplified(mail_part.content_type) == "text/html"
body = Nokogiri::HTML(body).text
end
message = user.send_messages.new body: body,
group: original_message.group,
private: original_message.private,