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
上级 9c928671
......@@ -15,8 +15,8 @@ def attachments
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?
......
......@@ -145,6 +145,10 @@ def []( key )
@header[key.downcase]
end
def sub_header(key, param)
(hdr = self[key]) ? hdr[param] : nil
end
alias fetch []
def []=( key, val )
......
......@@ -5,7 +5,7 @@ def subject(to_charset = 'utf-8')
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 @@ def body(to_charset = 'utf-8', &block)
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"]) : "")
......
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é.
----------------------------------------------------------------
......@@ -388,11 +388,17 @@ def test_decode_attachment_without_charset
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册