diff options
author | Go MAEDA <maeda@farend.jp> | 2019-03-03 08:17:59 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2019-03-03 08:17:59 +0000 |
commit | 77f35cb81841b4747ee54862c7ad0dc6b69ab1ca (patch) | |
tree | 6983efad7426c93b3a623b2bf4d4199511e0e471 /app/models/mail_handler.rb | |
parent | 917f9d9442a90a2734feac41e1ec8c76bc339227 (diff) | |
download | redmine-77f35cb81841b4747ee54862c7ad0dc6b69ab1ca.tar.gz redmine-77f35cb81841b4747ee54862c7ad0dc6b69ab1ca.zip |
Option to parse HTML part of multipart (HTML) emails first (#30838).
Patch by Yuichi HARADA.
git-svn-id: http://svn.redmine.org/redmine/trunk@17913 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/mail_handler.rb')
-rwxr-xr-x | app/models/mail_handler.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index be4b363b1..de59d6397 100755 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -447,16 +447,23 @@ class MailHandler < ActionMailer::Base end end - # Returns the text/plain part of the email - # If not found (eg. HTML-only email), returns the body with tags removed + # Returns the text content of the email. + # If the value of Setting.mail_handler_preferred_body_part is 'html', + # it returns text converted from the text/html part of the email. + # Otherwise, it returns text/plain part. 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 + parse_order = + if Setting.mail_handler_preferred_body_part == 'html' + ['text/html', 'text/plain'] + else + ['text/plain', 'text/html'] + end + parse_order.each do |mime_type| + @plain_text_body ||= email_parts_to_text(email.all_parts.select {|p| p.mime_type == mime_type}).presence + return @plain_text_body unless @plain_text_body.nil? + end # If there is still no body found, and there are no mime-parts defined, # we use the whole raw mail body |