diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index c100f8d..b3b323c 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -410,7 +410,7 @@ class MailHandler < ActionMailer::Base part.header[:content_disposition].try(:disposition_type) == 'attachment' end - @plain_text_body = parts.map {|p| Redmine::CodesetUtil.to_utf8(p.body.decoded, p.charset)}.join("\r\n") + @plain_text_body = parts.map {|p| Redmine::CodesetUtil.to_utf8(p.body.decoded, Mail::RubyVer.pick_encoding(p.charset).to_s)}.join("\r\n") # strip html tags and remove doctype directive if parts.any? {|p| p.mime_type == 'text/html'} diff --git a/test/fixtures/mail_handler/body_ks_c_5601-1987.eml b/test/fixtures/mail_handler/body_ks_c_5601-1987.eml new file mode 100644 index 0000000..e89ca5e --- /dev/null +++ b/test/fixtures/mail_handler/body_ks_c_5601-1987.eml @@ -0,0 +1,14 @@ +From: John Smith +To: "redmine@somenet.foo" +Subject: This is a test +Content-Type: multipart/alternative; + boundary="_c20d9cfa-d16a-43a3-a7e5-71da7877ab23_" + +--_c20d9cfa-d16a-43a3-a7e5-71da7877ab23_ +Content-Type: text/plain; charset="ks_c_5601-1987" +Content-Transfer-Encoding: base64 + +sO24v73AtM+02S4= + +--_c20d9cfa-d16a-43a3-a7e5-71da7877ab23_-- + diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 785d16f..18f4790 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -538,6 +538,22 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal ja, issue.subject end + def test_add_issue_with_korean_body + # Make sure mail bodies with a charset unknown to Ruby but known to the + # Mail gem are handled correctly + + issue = submit_email( + 'body_ks_c_5601-1987.eml', + :issue => {:project => 'ecookbook'} + ) + + assert_kind_of Issue, issue + + kr = "\xEA\xB3\xA0\xEB\xA7\x99\xEC\x8A\xB5\xEB\x8B\x88\xEB\x8B\xA4." + kr.force_encoding('UTF-8') if kr.respond_to?(:force_encoding) + assert_equal kr, issue.description + end + def test_add_issue_with_no_subject_header issue = submit_email( 'no_subject_header.eml',