Support receiving of signed multipart mails in messages plugin
This commit is contained in:
parent
564492afe4
commit
8e593f8629
1 changed files with 18 additions and 11 deletions
|
@ -20,17 +20,8 @@ class MessagesMailReceiver
|
||||||
def received(data)
|
def received(data)
|
||||||
mail = Mail.new data
|
mail = Mail.new data
|
||||||
|
|
||||||
mail_part = nil
|
mail_part = get_mail_part(mail)
|
||||||
if mail.multipart?
|
raise "No valid content could be found" if mail_part.nil?
|
||||||
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
|
|
||||||
|
|
||||||
body = mail_part.body.decoded
|
body = mail_part.body.decoded
|
||||||
unless mail_part.content_type_parameters.nil?
|
unless mail_part.content_type_parameters.nil?
|
||||||
|
@ -61,4 +52,20 @@ class MessagesMailReceiver
|
||||||
Resque.enqueue(MessageNotifier, FoodsoftConfig.scope, "message_deliver", message.id)
|
Resque.enqueue(MessageNotifier, FoodsoftConfig.scope, "message_deliver", message.id)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue