]> source.dussan.org Git - redmine.git/commitdiff
Merged r9796 from trunk.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 17 Jun 2012 08:51:04 +0000 (08:51 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 17 Jun 2012 08:51:04 +0000 (08:51 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.0-stable@9839 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 4a0b2ea0edc069db1d810418e022f6ec6d3fa6ab..520183c66e016b41eca24ad9ce21b37998d3f78a 100644 (file)
@@ -163,7 +163,7 @@ class MailHandler < ActionMailer::Base
     issue = Issue.new(:author => user, :project => project)
     issue.safe_attributes = issue_attributes_from_keywords(issue)
     issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)}
-    issue.subject = email.subject.to_s.chomp[0,255]
+    issue.subject = cleaned_up_subject
     if issue.subject.blank?
       issue.subject = '(no subject)'
     end
@@ -223,7 +223,7 @@ class MailHandler < ActionMailer::Base
       end
 
       if !message.locked?
-        reply = Message.new(:subject => email.subject.gsub(%r{^.*msg\d+\]}, '').strip,
+        reply = Message.new(:subject => cleaned_up_subject.gsub(%r{^.*msg\d+\]}, '').strip,
                             :content => cleaned_up_text_body)
         reply.author = user
         reply.board = message.board
@@ -364,6 +364,23 @@ class MailHandler < ActionMailer::Base
     cleanup_body(plain_text_body)
   end
 
+  def cleaned_up_subject
+    subject = email.subject.to_s
+    unless subject.respond_to?(:encoding)
+      # try to reencode to utf8 manually with ruby1.8
+      begin
+        if h = email.header[:subject]
+          if m = h.value.match(/^=\?([^\?]+)\?/)
+            subject = Redmine::CodesetUtil.to_utf8(subject, m[1])
+          end
+        end
+      rescue
+        # nop
+      end
+    end
+    subject.strip[0,255]
+  end
+
   def self.full_sanitizer
     @full_sanitizer ||= HTML::FullSanitizer.new
   end
diff --git a/test/fixtures/mail_handler/subject_as_iso-8859-1.eml b/test/fixtures/mail_handler/subject_as_iso-8859-1.eml
new file mode 100644 (file)
index 0000000..45f725b
--- /dev/null
@@ -0,0 +1,11 @@
+Content-Type: application/ms-tnef; name="winmail.dat"
+Content-Transfer-Encoding: binary
+From: John Smith <JSmith@somenet.foo>
+To: "redmine@somenet.foo" <redmine@somenet.foo>
+Subject: =?iso-8859-1?Q?Testmail_from_Webmail:_=E4_=F6_=FC...?=
+Date: Fri, 1 Jun 2012 14:39:38 +0200
+Message-ID: <87C31D42249DD0489D1A1444E3232DD7019D6183@foo.bar>
+Accept-Language: de-CH, en-US
+Content-Language: de-CH
+
+Fixture
index 8f916949ebc46b409e5d46cd2145ec234a9a1527..68a0c8f2e481467d163a9e3d3de34d56712a3903 100644 (file)
@@ -347,6 +347,15 @@ class MailHandlerTest < ActiveSupport::TestCase
     assert_equal 'caaf384198bcbc9563ab5c058acd73cd', attachment.digest
   end
 
+  def test_add_issue_with_iso_8859_1_subject
+    issue = submit_email(
+              'subject_as_iso-8859-1.eml',
+              :issue => {:project => 'ecookbook'}
+            )
+    assert_kind_of Issue, issue
+    assert_equal 'Testmail from Webmail: ä ö ü...', issue.subject
+  end
+
   def test_should_ignore_emails_from_locked_users
     User.find(2).lock!