Made the unquoted subject and body the default

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@964 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 553f115b
......@@ -66,13 +66,13 @@ Example:
def receive(email)
page = Page.find_by_address(email.to.first)
page.emails.create(
:subject => email.unquoted_subject, :body => email.unquoted_body_with_all_parts
:subject => email.subject, :body => email.body
)
if email.has_attachments?
for attachment in email.attachments
page.attachments.create({
:file => attachment, :description => email.unquoted_subject
:file => attachment, :description => email.subject
})
end
end
......
......@@ -261,6 +261,7 @@ def subject( default = nil )
default
end
end
alias quoted_subject subject
def subject=( str )
set_string_attr 'Subject', str
......
......@@ -322,7 +322,7 @@ def each( &block )
body_port().ropen {|f| f.each(&block) }
end
def body
def quoted_body
parse_body
@body_port.ropen {|f|
return f.read
......
......@@ -3,24 +3,25 @@
module TMail
class Mail
def unquoted_subject(to_charset = 'utf-8')
Unquoter.unquote_and_convert_to(subject || "", to_charset)
def subject(to_charset = 'utf-8')
Unquoter.unquote_and_convert_to(quoted_subject || "", to_charset)
end
def unquoted_body(to_charset = 'utf-8')
Unquoter.unquote_and_convert_to(body || "", to_charset, header["content-type"]["charset"])
Unquoter.unquote_and_convert_to(quoted_body || "", to_charset, header["content-type"]["charset"])
end
def unquoted_body_with_all_parts(to_charset = 'utf-9', &block)
def body(to_charset = 'utf-8', &block)
attachment_presenter = block || Proc.new { |file_name| "Attachment: #{file_name}\n" }
if multipart?
parts.collect { |part|
part.header["content-type"].main_type == "text" ?
part.unquoted_body : attachment_presenter.call(part.header["content-type"].params["name"])
part.unquoted_body(to_charset) :
attachment_presenter.call(part.header["content-type"].params["name"])
}.join
else
unquoted_body
unquoted_body(to_charset)
end
end
end
......
......@@ -212,5 +212,21 @@ def test_perform_deliveries_flag
assert_equal 1, ActionMailer::Base.deliveries.size
end
def test_unquote_subject
msg = <<EOF
From: me@example.com
Subject: =?utf-8?Q?testing_testing_=D6=A4?=
Content-Type: text/plain; charset=iso-8859-1
This_is_a_test
2 + 2 =3D 4
EOF
mail = TMail::Mail.parse(msg)
assert_equal "testing testing \326\244", mail.subject
assert_equal "=?utf-8?Q?testing_testing_=D6=A4?=", mail.quoted_subject
assert_equal "This is a test\n2 + 2 = 4\n", mail.body
assert_equal "This_is_a_test\n2 + 2 =3D 4\n", mail.quoted_body
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册