Fix handling multiple text parts in email (#13646).

Patch by Alex Shulgin.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11834 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2013-05-12 09:38:20 +00:00
parent 76a3298306
commit 9b7d312a0e
3 changed files with 75 additions and 4 deletions
+13 -4
View File
@@ -377,12 +377,21 @@ class MailHandler < ActionMailer::Base
def plain_text_body
return @plain_text_body unless @plain_text_body.nil?
part = email.text_part || email.html_part || email
@plain_text_body = Redmine::CodesetUtil.to_utf8(part.body.decoded, part.charset)
parts = if (text_parts = email.all_parts.select {|p| p.mime_type == 'text/plain'}).present?
text_parts
elsif (html_parts = email.all_parts.select {|p| p.mime_type == 'text/html'}).present?
html_parts
else
[email]
end
@plain_text_body = parts.map {|p| Redmine::CodesetUtil.to_utf8(p.body.decoded, p.charset)}.join("\r\n")
# strip html tags and remove doctype directive
@plain_text_body = strip_tags(@plain_text_body.strip)
@plain_text_body.sub! %r{^<!DOCTYPE .*$}, ''
if parts.any? {|p| p.mime_type == 'text/html'}
@plain_text_body = strip_tags(@plain_text_body.strip)
@plain_text_body.sub! %r{^<!DOCTYPE .*$}, ''
end
@plain_text_body
end