Support receiving of signed multipart mails in messages plugin

This commit is contained in:
Patrick Gansterer 2017-10-19 14:57:42 +02:00
parent 564492afe4
commit 8e593f8629
1 changed files with 18 additions and 11 deletions

View File

@ -20,17 +20,8 @@ class MessagesMailReceiver
def received(data)
mail = Mail.new data
mail_part = nil
if mail.multipart?
for part in mail.parts
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
end
mail_part = get_mail_part(mail)
raise "No valid content could be found" if mail_part.nil?
body = mail_part.body.decoded
unless mail_part.content_type_parameters.nil?
@ -61,4 +52,20 @@ class MessagesMailReceiver
Resque.enqueue(MessageNotifier, FoodsoftConfig.scope, "message_deliver", message.id)
end
private
def get_mail_part(mail)
return mail unless mail.multipart?
mail_part = nil
for part in mail.parts
part = get_mail_part(part)
content_type = MIME::Type.simplified(part.content_type)
if content_type == "text/plain" || !mail_part && content_type == "text/html"
mail_part = part
end
end
mail_part
end
end