summaryrefslogtreecommitdiffstats
path: root/app/models/mail_handler.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-03-07 17:54:09 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-03-07 17:54:09 +0000
commita63908c5eda2747eb40c6880d7b04ee8b706d9fe (patch)
treebbb36d119dc41f1144fb2af9c82f70ec3eb44dda /app/models/mail_handler.rb
parent58ee62e23990799f1c6d733e1a9a7f046d004816 (diff)
downloadredmine-a63908c5eda2747eb40c6880d7b04ee8b706d9fe.tar.gz
redmine-a63908c5eda2747eb40c6880d7b04ee8b706d9fe.zip
Emails with no text or html Content not handled properly (#25269, #25256).
Patch by Felix Schäfer. git-svn-id: http://svn.redmine.org/redmine/trunk@16379 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/mail_handler.rb')
-rw-r--r--app/models/mail_handler.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 53f37a29e..dc033de75 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -445,13 +445,19 @@ class MailHandler < ActionMailer::Base
def plain_text_body
return @plain_text_body unless @plain_text_body.nil?
+ # check if we have any plain-text parts with content
@plain_text_body = email_parts_to_text(email.all_parts.select {|p| p.mime_type == 'text/plain'}).presence
+ # if not, we try to parse the body from the HTML-parts
@plain_text_body ||= email_parts_to_text(email.all_parts.select {|p| p.mime_type == 'text/html'}).presence
- @plain_text_body ||= email_parts_to_text([email])
+ # If there is still no body found, and there are no mime-parts defined,
+ # we use the whole raw mail body
+ @plain_text_body ||= email_parts_to_text([email]).presence if email.all_parts.empty?
- @plain_text_body
+ # As a fallback we return an empty plain text body (e.g. if we have only
+ # empty text parts but a non-text attachment)
+ @plain_text_body ||= ""
end
def email_parts_to_text(parts)