diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index fd2e25fb5..7a448e575 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -546,6 +546,7 @@ class MailHandler < ActionMailer::Base # Converts a plain/text email body to text def plain_text_body_to_text(text) + return nil if MailHandler::EmptyContentPolicy.new(text).suppress? # Removes leading spaces that would cause the line to be rendered as # preformatted text with textile text.gsub(/^ +(?![*#])/, '') @@ -644,4 +645,24 @@ class MailHandler < ActionMailer::Base def find_assignee_from_keyword(keyword, issue) Principal.detect_by_keyword(issue.assignable_users, keyword) end + + class EmptyContentPolicy + attr_accessor :text + + patterns = [ + '\AYour email client does not support HTML messages.\z', + '\AKlicken Sie hier\p{Space}+http\p{Graph}+\p{Space}+für die Online-Version.\z' + ] + EMPTY_CONTENT_RE = Regexp.new(patterns.join('|'), Regexp::IGNORECASE) + + def initialize(text) + self.text = text + end + + def suppress? + return true if text.chomp('') =~ EMPTY_CONTENT_RE + + false + end + end end diff --git a/test/fixtures/mail_handler/see_html_text_part.eml b/test/fixtures/mail_handler/see_html_text_part.eml new file mode 100644 index 000000000..b9f18a678 --- /dev/null +++ b/test/fixtures/mail_handler/see_html_text_part.eml @@ -0,0 +1,47 @@ +From JSmith@somenet.foo Fri Mar 22 08:30:28 2013 +From: John Smith +Content-Type: multipart/mixed; boundary="Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9" +Message-Id: +Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) +Subject: Test with an empty text part +Date: Fri, 22 Mar 2013 17:30:20 +0200 +To: redmine@somenet.foo +X-Mailer: Apple Mail (2.1503) + + + +--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; + charset=us-ascii + +Your email client does not support HTML messages. + + +--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 +Content-Type: text/plain; charset=utf-8 +Content-Transfer-Encoding: quoted-printable + +Klicken Sie hier + https://example.com + + f=C3=BCr die Online-Version. + +--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; + charset=us-ascii + + + + + + + +

The html part.

+ + + + +--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9-- diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 3fd3ce072..fb0f59a3a 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -713,6 +713,11 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal 'The html part.', issue.description end + def test_see_html_text_part_should_not_stop_looking_for_content + issue = submit_email('see_html_text_part.eml', :issue => {:project => 'ecookbook'}) + assert_equal 'The html part.', issue.description + end + def test_empty_text_and_html_part_should_make_an_empty_description issue = submit_email('empty_text_and_html_part.eml', :issue => {:project => 'ecookbook'}) assert_equal '', issue.description