diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-05-10 15:30:18 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-05-10 15:30:18 +0000 |
commit | ee6882614f46c33277c36504d125672bb8f6c34e (patch) | |
tree | b4ea625cf335a5ac98f015410657e5ba6a5c82e8 | |
parent | 9c9286710268ff124ffe68727030dbe401bbc3c2 (diff) | |
download | rails-ee6882614f46c33277c36504d125672bb8f6c34e.tar.gz rails-ee6882614f46c33277c36504d125672bb8f6c34e.tar.bz2 rails-ee6882614f46c33277c36504d125672bb8f6c34e.zip |
Step cautiously around subheaders in TMail #1285 [Jamis Buck]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1301 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail/attachments.rb | 4 | ||||
-rwxr-xr-x | actionmailer/lib/action_mailer/vendor/tmail/mail.rb | 4 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail/quoting.rb | 4 | ||||
-rw-r--r-- | actionmailer/test/fixtures/raw_email5 | 19 | ||||
-rwxr-xr-x | actionmailer/test/mail_service_test.rb | 8 |
5 files changed, 34 insertions, 5 deletions
diff --git a/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb b/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb index e78d2f91d2..e402b0545f 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb @@ -15,8 +15,8 @@ module TMail parts.collect { |part| if part.header["content-type"].main_type != "text" content = part.body # unquoted automatically by TMail#body - file_name = part.header["content-type"].params["name"] || - part.header["content-disposition"].params["filename"] + file_name = part.sub_header("content-type", "name") || + part.sub_header("content-disposition", "filename") next if file_name.blank? || content.blank? diff --git a/actionmailer/lib/action_mailer/vendor/tmail/mail.rb b/actionmailer/lib/action_mailer/vendor/tmail/mail.rb index 22bc8edcca..9111a65042 100755 --- a/actionmailer/lib/action_mailer/vendor/tmail/mail.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail/mail.rb @@ -145,6 +145,10 @@ module TMail @header[key.downcase] end + def sub_header(key, param) + (hdr = self[key]) ? hdr[param] : nil + end + alias fetch [] def []=( key, val ) diff --git a/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb b/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb index 0c2653a6e0..6494b592d6 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb @@ -5,7 +5,7 @@ module TMail end def unquoted_body(to_charset = 'utf-8') - from_charset = header['content-type']['charset'] rescue 'us-ascii' + from_charset = sub_header("content-type", "charset") case (content_transfer_encoding || "7bit").downcase when "quoted-printable" Unquoter.unquote_quoted_printable_and_convert_to(quoted_body, @@ -27,7 +27,7 @@ module TMail if multipart? parts.collect { |part| - header = part.header["content-type"] + header = part["content-type"] header && header.main_type == "text" ? part.unquoted_body(to_charset) : (header ? attachment_presenter.call(header.params["name"]) : "") diff --git a/actionmailer/test/fixtures/raw_email5 b/actionmailer/test/fixtures/raw_email5 new file mode 100644 index 0000000000..151c631471 --- /dev/null +++ b/actionmailer/test/fixtures/raw_email5 @@ -0,0 +1,19 @@ +Return-Path: <xxx@xxxx.xxx> +Received: from xxx.xxxx.xxx by xxx.xxxx.xxx with ESMTP id C1B953B4CB6 for <xxxxx@Exxx.xxxx.xxx>; Tue, 10 May 2005 15:27:05 -0500 +Received: from SMS-GTYxxx.xxxx.xxx by xxx.xxxx.xxx with ESMTP id ca for <xxxxx@Exxx.xxxx.xxx>; Tue, 10 May 2005 15:27:04 -0500 +Received: from xxx.xxxx.xxx by SMS-GTYxxx.xxxx.xxx with ESMTP id j4AKR3r23323 for <xxxxx@Exxx.xxxx.xxx>; Tue, 10 May 2005 15:27:03 -0500 +Date: Tue, 10 May 2005 15:27:03 -0500 +From: xxx@xxxx.xxx +Sender: xxx@xxxx.xxx +To: xxxxxxxxxxx@xxxx.xxxx.xxx +Message-Id: <xxx@xxxx.xxx> +X-Original-To: xxxxxxxxxxx@xxxx.xxxx.xxx +Delivered-To: xxx@xxxx.xxx +Importance: normal + +Test test. Hi. Waving. m + +---------------------------------------------------------------- +Sent via Bell Mobility's Text Messaging service. +Envoyé par le service de messagerie texte de Bell Mobilité. +---------------------------------------------------------------- diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 8609d0c16c..733ec61e41 100755 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -388,11 +388,17 @@ EOF assert_equal 1026, attachment.read.length end - def test_decode_message_without_content_type + def test_decode_part_without_content_type fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email4") mail = TMail::Mail.parse(fixture) assert_nothing_raised { mail.body } end + def test_decode_message_without_content_type + fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email5") + mail = TMail::Mail.parse(fixture) + assert_nothing_raised { mail.body } + end + end |