diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 2aaa8bbf0..deb27e22a 100755 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -44,7 +44,7 @@ class MailHandler < ActionMailer::Base options[:no_permission_check] = (options[:no_permission_check].to_s == '1') ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload| - mail = Mail.new(raw_mail.b) + mail = Mail.new(Mail::Utilities.binary_unsafe_to_crlf(raw_mail.b)) set_payload_for_mail(payload, mail) new.receive(mail, options) end diff --git a/test/fixtures/mail_handler/thunderbird_with_utf8_body_and_lf_lineterminator_and_attachment.eml b/test/fixtures/mail_handler/thunderbird_with_utf8_body_and_lf_lineterminator_and_attachment.eml new file mode 100644 index 000000000..949eb2dd0 --- /dev/null +++ b/test/fixtures/mail_handler/thunderbird_with_utf8_body_and_lf_lineterminator_and_attachment.eml @@ -0,0 +1,32 @@ +To: redmine@somenet.foo +From: John Smith +Subject: =?UTF-8?B?44OG44K544OI44Oh44O844Or?= +Message-ID: +Date: Mon, 10 Jun 2019 13:39:21 +0900 +User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) + Gecko/20100101 Thunderbird/60.7.0 +MIME-Version: 1.0 +Content-Type: multipart/mixed; + boundary="------------6FE4347B4294DF3B19BB9898" +Content-Language: en-US + +This is a multi-part message in MIME format. +--------------6FE4347B4294DF3B19BB9898 +Content-Type: text/plain; charset=utf-8; format=flowed +Content-Transfer-Encoding: 8bit + +To:redmine + + テストメールを送信します。 + +--------------6FE4347B4294DF3B19BB9898 +Content-Type: application/zip; x-mac-type="0"; x-mac-creator="0"; + name="test.zip" +Content-Transfer-Encoding: base64 +Content-Disposition: attachment; + filename="test.zip" + +UEsDBBQAAAAAAE8/xU4Mfn/YBAAAAAQAAAAIAAAAdGVzdC50eHR0ZXN0UEsBAhQAFAAAAAAA +Tz/FTgx+f9gEAAAABAAAAAgAAAAAAAAAAQAgAAAAAAAAAHRlc3QudHh0UEsFBgAAAAABAAEA +NgAAACoAAAAAAA== +--------------6FE4347B4294DF3B19BB9898-- diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index ed064f6f7..bb3cb58d3 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -415,6 +415,26 @@ class MailHandlerTest < ActiveSupport::TestCase assert mail.subject.include?('New ticket on a given project') end + def test_add_issue_with_utf8_body_and_lf_line_terminator_and_attachment + assert_difference 'Issue.count' do + issue = submit_email( + 'thunderbird_with_utf8_body_and_lf_lineterminator_and_attachment.eml', + :issue => {:project => 'ecookbook'} + ) do |email| + # Ensure that line terminators are LF + email.gsub!(/\r\n?/, "\n") + end + + assert issue.is_a?(Issue) + assert_equal 'テストメール', issue.subject + assert_equal "To:redmine\r\n\r\n テストメールを送信します。", issue.description + + assert_equal 1, issue.attachments.size + assert_equal 'test.zip', issue.attachments.first.filename + assert_equal 118, issue.attachments.first.filesize + end + end + def test_created_user_should_be_added_to_groups group1 = Group.generate! group2 = Group.generate!