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
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
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
--- /dev/null
+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
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!