]> source.dussan.org Git - redmine.git/commitdiff
Merged r10812 from trunk (#12375)
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Fri, 16 Nov 2012 07:52:05 +0000 (07:52 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Fri, 16 Nov 2012 07:52:05 +0000 (07:52 +0000)
fix receiving mail subject broken which does not begin with encoding name.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.1-stable@10816 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 8a5925cab07d8528db3c8179e03aab5834698310..c6e3d8ff25dffbc55984e23a64e34807bee364bd 100644 (file)
@@ -373,7 +373,8 @@ class MailHandler < ActionMailer::Base
       # try to reencode to utf8 manually with ruby1.8
       begin
         if h = email.header[:subject]
-          if m = h.value.match(/^=\?([^\?]+)\?/)
+          # http://tools.ietf.org/html/rfc2047#section-4
+          if m = h.value.match(/=\?([^\?]+)\?[BbQq]\?/)
             subject = Redmine::CodesetUtil.to_utf8(subject, m[1])
           end
         end
diff --git a/test/fixtures/mail_handler/subject_japanese_2.eml b/test/fixtures/mail_handler/subject_japanese_2.eml
new file mode 100644 (file)
index 0000000..d25d478
--- /dev/null
@@ -0,0 +1,7 @@
+From: John Smith <JSmith@somenet.foo>
+To: "redmine@somenet.foo" <redmine@somenet.foo>
+Subject: Re: =?iso-2022-jp?b?GyRCJUYlOSVIGyhCCg=?=
+Date: Fri, 1 Jun 2012 14:39:38 +0200
+Message-ID: <87C31D42249DD0489D1A1444E3232DD7019D6183@foo.bar>
+
+Fixture
index fd8e1404f571f6117c4dafe3dfcae64a3ddd2e8b..a0c5645d91e7b3b6039041e4a5b0db94e436da52 100644 (file)
@@ -393,6 +393,17 @@ class MailHandlerTest < ActiveSupport::TestCase
     assert_equal ja, issue.subject
   end
 
+  def test_add_issue_with_mixed_japanese_subject
+    issue = submit_email(
+              'subject_japanese_2.eml',
+              :issue => {:project => 'ecookbook'}
+            )
+    assert_kind_of Issue, issue
+    ja = "Re: \xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88"
+    ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
+    assert_equal ja, issue.subject
+  end
+
   def test_should_ignore_emails_from_locked_users
     User.find(2).lock!