]> source.dussan.org Git - redmine.git/commitdiff
support more character encoding in incoming emails (#15785)
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 1 Jan 2014 05:54:28 +0000 (05:54 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 1 Jan 2014 05:54:28 +0000 (05:54 +0000)
Supporting encodings of iconv on Ruby 1.8 depend on iconv implementation.
glibc-common-2.12-1.132 on CentOS6 does not support ks_c_5601-1987.

Contributed by Felix Schäfer.

git-svn-id: http://svn.redmine.org/redmine/trunk@12474 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
test/fixtures/mail_handler/body_ks_c_5601-1987.eml [new file with mode: 0644]
test/unit/mail_handler_test.rb

index c100f8d977ab2adb2d255461e3fe54b1440f163d..7a420942909de89f3baf53cdcc5de16c8e2afe47 100644 (file)
@@ -410,7 +410,11 @@ 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 do |p|
+      body_charset = p.charset.respond_to?(:force_encoding) ?
+                       Mail::RubyVer.pick_encoding(p.charset).to_s : p.charset
+      Redmine::CodesetUtil.to_utf8(p.body.decoded, body_charset)
+    end.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 (file)
index 0000000..e89ca5e
--- /dev/null
@@ -0,0 +1,14 @@
+From: John Smith <JSmith@somenet.foo>
+To: "redmine@somenet.foo" <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_--
+
index 785d16ffd1de80c5e79d8b8338e1f93de0fb8b35..f6ba8b0f7e0cb96e117923ad74c398341de15fd2 100644 (file)
@@ -538,6 +538,23 @@ 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 2.5.4 are handled correctly
+    kr = "\xEA\xB3\xA0\xEB\xA7\x99\xEC\x8A\xB5\xEB\x8B\x88\xEB\x8B\xA4."
+    if !kr.respond_to?(:force_encoding)
+      puts "\nOn Ruby 1.8, skip Korean encoding mail body test"
+    else
+      kr.force_encoding('UTF-8')
+      issue = submit_email(
+              'body_ks_c_5601-1987.eml',
+              :issue => {:project => 'ecookbook'}
+            )
+      assert_kind_of Issue, issue
+      assert_equal kr, issue.description
+    end
+  end
+
   def test_add_issue_with_no_subject_header
     issue = submit_email(
               'no_subject_header.eml',