From: Jean-Philippe Lang Date: Sun, 10 Jun 2012 08:15:22 +0000 (+0000) Subject: Fixed: German umlauts in Subject get striped with ruby1.8 (#11065). X-Git-Tag: 2.1.0~470 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=26ff9e1c260b6cbb02371f72047e3108a93aee75;p=redmine.git Fixed: German umlauts in Subject get striped with ruby1.8 (#11065). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9796 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 4a0b2ea0e..520183c66 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -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 index 000000000..45f725bdf --- /dev/null +++ b/test/fixtures/mail_handler/subject_as_iso-8859-1.eml @@ -0,0 +1,11 @@ +Content-Type: application/ms-tnef; name="winmail.dat" +Content-Transfer-Encoding: binary +From: John Smith +To: "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 diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 8f916949e..68a0c8f2e 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -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!