1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Improved address header processing

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1161 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-04-13 17:49:24 +00:00
parent f3e5e07982
commit 54cc595dff
2 changed files with 13 additions and 13 deletions

View file

@ -168,9 +168,9 @@ module ActionMailer #:nodoc:
def quote_address_if_necessary(address, charset)
if Array === address
address.map { |a| quote_address_if_necessary(a, charset) }
elsif address =~ /^(\S.+)\s+(<.*>)$/
elsif address =~ /^(\S.*)\s+(<.*>)$/
address = $2
phrase = quote_if_necessary($1, charset)
phrase = quote_if_necessary($1.gsub(/^['"](.*)['"]$/, '\1'), charset)
"#{phrase} #{address}"
else
address

View file

@ -66,11 +66,11 @@ class TestMailer < ActionMailer::Base
def utf8_body(recipient)
@recipients = recipient
@subject = "testing utf-8 body"
@from = "김치통 <kimchi@example.net.kr>"
@from = "Foo áëô îü <extended@example.net>"
@sent_on = Time.local 2004, 12, 12
@cc = "김치통 <kimchi@example.net.kr>"
@bcc = "김치통 <kimchi@example.net.kr>"
@body = "안녕하세요!"
@cc = "Foo áëô îü <extended@example.net>"
@bcc = "Foo áëô îü <extended@example.net>"
@body = "åœö blah"
@charset = "utf-8"
end
end
@ -277,34 +277,34 @@ EOF
end
def test_utf8_body_is_not_quoted
@recipient = "김치통 <kimchi@example.net.kr>"
@recipient = "Foo áëô îü <extended@example.net>"
expected = new_mail "utf-8"
expected.to = TestMailer.quote_address_if_necessary @recipient, "utf-8"
expected.subject = "testing utf-8 body"
expected.body = "안녕하세요!"
expected.body = "åœö blah"
expected.from = TestMailer.quote_address_if_necessary @recipient, "utf-8"
expected.cc = TestMailer.quote_address_if_necessary @recipient, "utf-8"
expected.bcc = TestMailer.quote_address_if_necessary @recipient, "utf-8"
expected.date = Time.local 2004, 12, 12
created = TestMailer.create_utf8_body @recipient
assert_match(/안녕하세요!/, created.encoded)
assert_match(/åœö blah/, created.encoded)
end
def test_multiple_utf8_recipients
@recipient = ["김치통 <kimchi@example.net.kr>", "\"Example Recipient\" <me@example.com>"]
@recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"]
expected = new_mail "utf-8"
expected.to = TestMailer.quote_address_if_necessary @recipient, "utf-8"
expected.subject = "testing utf-8 body"
expected.body = "안녕하세요!"
expected.body = "åœö blah"
expected.from = TestMailer.quote_address_if_necessary @recipient.first, "utf-8"
expected.cc = TestMailer.quote_address_if_necessary @recipient, "utf-8"
expected.bcc = TestMailer.quote_address_if_necessary @recipient, "utf-8"
expected.date = Time.local 2004, 12, 12
created = TestMailer.create_utf8_body @recipient
assert_match(/\nFrom: =\?.*?\?= <kimchi@example.net.kr>\r/, created.encoded)
assert_match(/\nTo: =\?.*?\?= <kimchi.*?>, Example Recipient <me/, created.encoded)
assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded)
assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, Example Recipient <me/, created.encoded)
end
end