From 54cc595dff2564d6cb48c40709637170bca79837 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 13 Apr 2005 17:49:24 +0000 Subject: [PATCH] Improved address header processing git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1161 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionmailer/lib/action_mailer/base.rb | 4 ++-- actionmailer/test/mail_service_test.rb | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 27a0c8e19c..b731880570 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -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 diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index d5d24b2640..b5d488a02b 100755 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -66,11 +66,11 @@ class TestMailer < ActionMailer::Base def utf8_body(recipient) @recipients = recipient @subject = "testing utf-8 body" - @from = "김치통 " + @from = "Foo áëô îü " @sent_on = Time.local 2004, 12, 12 - @cc = "김치통 " - @bcc = "김치통 " - @body = "안녕하세요!" + @cc = "Foo áëô îü " + @bcc = "Foo áëô îü " + @body = "åœö blah" @charset = "utf-8" end end @@ -277,34 +277,34 @@ EOF end def test_utf8_body_is_not_quoted - @recipient = "김치통 " + @recipient = "Foo áëô îü " 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 = ["김치통 ", "\"Example Recipient\" "] + @recipient = ["\"Foo áëô îü\" ", "\"Example Recipient\" "] 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: =\?.*?\?= \r/, created.encoded) - assert_match(/\nTo: =\?.*?\?= , Example Recipient \r/, created.encoded) + assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= , Example Recipient