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
This commit is contained in:
David Heinemeier Hansson
2005-05-10 15:30:18 +00:00
parent 9c92867102
commit ee6882614f
5 changed files with 34 additions and 5 deletions

View File

@@ -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?

View File

@@ -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 )

View File

@@ -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"]) : "")

19
actionmailer/test/fixtures/raw_email5 vendored Normal file
View File

@@ -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é.
----------------------------------------------------------------

View File

@@ -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