1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
Description: Fix parsing of unquoted attachment filenames
Upstream commit d3f1d826 introduced a problem when parsing Content-Disposition
headers with unquoted filenames.
Author: Jérémy Bobbio <lunar@debian.org>
Last-Update: 2013-04-24
lib/tmail/utils.rb | 2 +-
test/test_attachments.rb | 1 +
test/test_mail.rb | 11 +++++++++++
3 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/lib/tmail/utils.rb b/lib/tmail/utils.rb
index 68e5898..5c395d3 100644
--- a/lib/tmail/utils.rb
+++ b/lib/tmail/utils.rb
@@ -350,7 +350,7 @@ module TMail
head, should_quoted, tail = $~.captures
# head: "; name="
# should_quoted: "=?ISO-2022-JP?B?...=?="
- head << quote_token(should_quoted) << tail
+ head << quote_token(should_quoted.strip) << tail
}
end
diff --git a/test/test_attachments.rb b/test/test_attachments.rb
index 86dcb40..72f53d0 100644
--- a/test/test_attachments.rb
+++ b/test/test_attachments.rb
@@ -79,6 +79,7 @@ HERE
fixture = File.read(File.dirname(__FILE__) + "/fixtures/unquoted_filename_in_attachment")
mail = TMail::Mail.parse(fixture)
assert_equal("image/png", mail.attachments.first.content_type)
+ assert_equal("Picture 7.png", mail.attachments.first.original_filename)
end
def test_unquoted_apple_mail_content_type
diff --git a/test/test_mail.rb b/test/test_mail.rb
index b63f497..52f26da 100644
--- a/test/test_mail.rb
+++ b/test/test_mail.rb
@@ -530,6 +530,17 @@ EOF
assert_equal(output, mail.to_s)
end
+ def test_mail_to_s_with_unquoted_filename
+ msg = <<EOF
+From: mikel@example.com
+Subject: =?utf-8?Q?testing_testing_=D6=A4?=
+Content-Disposition: attachment; filename=README.txt.pif
+
+The body
+EOF
+ assert_equal(msg, TMail::Mail.parse(msg).to_s)
+ end
+
def test_mail_to_s_with_filename_discards_quotes_as_needed
msg = <<EOF
From: mikel@example.com
--
|