Permalink
Browse files

Merge commit 'technoweenie/mime_charset_bug'

  • Loading branch information...
2 parents d3f1d82 + 53f61d1 commit 2c68e8ade82e098cf4c3c31f2b6a322bac31b3d3 @mikel committed Aug 7, 2009
Showing with 28 additions and 2 deletions.
  1. +11 −1 lib/tmail/interface.rb
  2. +1 −1 lib/tmail/quoting.rb
  3. +16 −0 test/test_mail.rb
View
@@ -865,7 +865,17 @@ def charset( default = nil )
if h = @header['content-type']
h['charset'] or default
else
- default
+ mime_version_charset || default
+ end
+ end
+
+ # some weird emails come with the charset specified in the mime-version header:
+ #
+ # #<TMail::MimeVersionHeader "1.0\n charset=\"gb2312\"">
+ #
+ def mime_version_charset
+ if header['mime-version'].inspect =~ /charset=('|\\")?([^\\"']+)/
+ $2
end
end
View
@@ -10,7 +10,7 @@ def subject(to_charset = 'utf-8')
end
def unquoted_body(to_charset = 'utf-8')
- from_charset = sub_header("content-type", "charset")
+ from_charset = charset
case (content_transfer_encoding || "7bit").downcase
when "quoted-printable"
# the default charset is set to iso-8859-1 instead of 'us-ascii'.
View
@@ -416,6 +416,22 @@ def test_unquote_base64_body
assert_equal "VGhlIGJvZHk=", mail.quoted_body.strip
end
+ def test_unquote_base64_body_with_invalid_charset
+ msg = <<EOF
+From: "2009-07-02 21:53:01" <sender@example.com>
+Subject: unqoute base64 body with invalid charset
+MIME-Version: 1.0
+ charset="gb2312"
+Content-Transfer-Encoding: base64
+
+RGVhciBTaXJzLCANCldlIGFyZSBnaXZlbiB0byB1bmRlcnN0YW5kIHRoYXQg
+eW91IGFyZSAgTWFudWZhY3R1cmVyIG9mICBwbHN0aWMgIEJvdHRsZXMNCkFk
+ZKO6IGJsYWggQ2hpbmE=
+EOF
+ mail = TMail::Mail.parse(msg)
+ assert_equal "Dear Sirs, \r\nWe are given to understand that you are Manufacturer of plstic Bottles\r\nAdd: blah China", mail.body.strip
+ end
+
def test_message_id
assert_nil @mail.message_id
assert_equal 1, @mail.message_id(1)

0 comments on commit 2c68e8a

Please sign in to comment.