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