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: ...@@ -66,13 +66,13 @@ Example:
def receive(email) def receive(email)
page = Page.find_by_address(email.to.first) page = Page.find_by_address(email.to.first)
page.emails.create( page.emails.create(
:subject => email.unquoted_subject, :body => email.unquoted_body_with_all_parts :subject => email.subject, :body => email.body
) )
if email.has_attachments? if email.has_attachments?
for attachment in email.attachments for attachment in email.attachments
page.attachments.create({ page.attachments.create({
:file => attachment, :description => email.unquoted_subject :file => attachment, :description => email.subject
}) })
end end
end end
......
...@@ -261,6 +261,7 @@ def subject( default = nil ) ...@@ -261,6 +261,7 @@ def subject( default = nil )
default default
end end
end end
alias quoted_subject subject
def subject=( str ) def subject=( str )
set_string_attr 'Subject', str set_string_attr 'Subject', str
......
...@@ -322,7 +322,7 @@ def each( &block ) ...@@ -322,7 +322,7 @@ def each( &block )
body_port().ropen {|f| f.each(&block) } body_port().ropen {|f| f.each(&block) }
end end
def body def quoted_body
parse_body parse_body
@body_port.ropen {|f| @body_port.ropen {|f|
return f.read return f.read
......
...@@ -3,24 +3,25 @@ ...@@ -3,24 +3,25 @@
module TMail module TMail
class Mail class Mail
def unquoted_subject(to_charset = 'utf-8') def subject(to_charset = 'utf-8')
Unquoter.unquote_and_convert_to(subject || "", to_charset) Unquoter.unquote_and_convert_to(quoted_subject || "", to_charset)
end end
def unquoted_body(to_charset = 'utf-8') 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 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" } attachment_presenter = block || Proc.new { |file_name| "Attachment: #{file_name}\n" }
if multipart? if multipart?
parts.collect { |part| parts.collect { |part|
part.header["content-type"].main_type == "text" ? 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 }.join
else else
unquoted_body unquoted_body(to_charset)
end end
end end
end end
......
...@@ -212,5 +212,21 @@ def test_perform_deliveries_flag ...@@ -212,5 +212,21 @@ def test_perform_deliveries_flag
assert_equal 1, ActionMailer::Base.deliveries.size assert_equal 1, ActionMailer::Base.deliveries.size
end 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 end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册