summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>2012-11-16 06:19:42 +0000
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>2012-11-16 06:19:42 +0000
commit617cb7ac53eeb58d3d022656b71317da5dfa3a8a (patch)
treec3f67608c8dc94c586998bbabb2957a98a956f79
parent1da74009cd3f7f39de5f1b50fbb0ce3eb80a6f44 (diff)
downloadredmine-617cb7ac53eeb58d3d022656b71317da5dfa3a8a.tar.gz
redmine-617cb7ac53eeb58d3d022656b71317da5dfa3a8a.zip
fix receiving mail subject broken which does not begin with encoding name (#12375)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10812 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/mail_handler.rb3
-rw-r--r--test/fixtures/mail_handler/subject_japanese_2.eml7
-rw-r--r--test/unit/mail_handler_test.rb11
3 files changed, 20 insertions, 1 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 3eacf3c19..3da93852d 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -377,7 +377,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
index 000000000..d25d47863
--- /dev/null
+++ b/test/fixtures/mail_handler/subject_japanese_2.eml
@@ -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
diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb
index 7eea11f84..ba1f3ebb4 100644
--- a/test/unit/mail_handler_test.rb
+++ b/test/unit/mail_handler_test.rb
@@ -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!