From ce7175f9f0e5231c568924bc68edbd2cb36ae5e8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 10 Jun 2019 11:41:31 +0000 Subject: [PATCH] Merged r18245 to 4.0-stable (#31365). git-svn-id: http://svn.redmine.org/redmine/branches/4.0-stable@18246 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- config/initializers/10-patches.rb | 14 ++++++++++++++ .../ticket_with_split_bytes_subject.eml | 9 +++++++++ test/unit/mail_handler_test.rb | 11 +++++++++++ 3 files changed, 34 insertions(+) create mode 100644 test/fixtures/mail_handler/ticket_with_split_bytes_subject.eml diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb index 8d73eba2c..c1c24fc96 100644 --- a/config/initializers/10-patches.rb +++ b/config/initializers/10-patches.rb @@ -105,6 +105,20 @@ end require 'mail' +module Mail + class SubjectField + # Fixed that the issue subject may be broken if the subject field in the + # receiving email is split into multiple lines + def initialize(value = nil, charset = 'utf-8') + if mime_encode = /^(=\?\S+\?\S\?)/.match(value).to_a[1] + value.gsub!(/\?=\s+#{Regexp.escape(mime_encode)}/, '') + end + self.charset = charset + super(CAPITALIZED_FIELD, value, charset) + end + end +end + module DeliveryMethods class TmpFile def initialize(*args); end diff --git a/test/fixtures/mail_handler/ticket_with_split_bytes_subject.eml b/test/fixtures/mail_handler/ticket_with_split_bytes_subject.eml new file mode 100644 index 000000000..52b8099e9 --- /dev/null +++ b/test/fixtures/mail_handler/ticket_with_split_bytes_subject.eml @@ -0,0 +1,9 @@ +Date: Mon, 13 May 2019 13:39:29 +0900 +Message-ID: +Subject: =?utf-8?B?zrHOss6zzrTOtc62zrfOuM65zrrOu868zr3Ovs6/z4DPgc+Cz4PPhM+Fz4bP?= + =?utf-8?B?h8+Iz4k=?= +From: +To: +Content-Type: text/plain + +Split bytes subject. diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 940dce5c4..45dc63237 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -1133,6 +1133,17 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal issue.subject, 'New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say...'[0,255] end + def test_email_with_split_bytes_subject + issue = submit_email( + 'ticket_with_split_bytes_subject.eml', + :issue => {:project => 'ecookbook'}, + :no_permission_check => '1', + :unknown_user => 'accept' + ) + assert issue.is_a?(Issue) + assert_equal 'αβγδεζηθικλμνξοπρςστυφχψω', issue.subject + end + def test_first_keyword_should_be_matched issue = submit_email('ticket_with_duplicate_keyword.eml', :allow_override => 'priority') assert issue.is_a?(Issue) -- 2.39.5