提交 dbcf01e6 编写于 作者: M Mikel Lindsaar

Removing quoting.rb, upgrade to 2.1.3.6, changing all utf-8 references to...

Removing quoting.rb, upgrade to 2.1.3.6, changing all utf-8 references to UTF-8, updating tests where incorrect encoding
上级 8f22be04
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
ActionMailer::Base.register_interceptor calls Mail.register_interceptor ActionMailer::Base.register_interceptor calls Mail.register_interceptor
ActionMailer::Base.register_observer calls Mail.register_observer ActionMailer::Base.register_observer calls Mail.register_observer
* Removed quoting.rb and refactored for Mail to take responsibility of all quoting and auto encoding requirements for the header.
* Fixed several tests which had incorrect encoding.
* Changed all utf-8 to UTF-8 for consistency
* Whole new API added with tests. See base.rb for full details. Old API is deprecated. * Whole new API added with tests. See base.rb for full details. Old API is deprecated.
......
...@@ -20,6 +20,6 @@ ...@@ -20,6 +20,6 @@
s.has_rdoc = true s.has_rdoc = true
s.add_dependency('actionpack', version) s.add_dependency('actionpack', version)
s.add_dependency('mail', '~> 2.1.5.5') s.add_dependency('mail', '~> 2.1.5.6')
s.add_dependency('text-format', '~> 1.0.0') s.add_dependency('text-format', '~> 1.0.0')
end end
...@@ -207,7 +207,7 @@ module ActionMailer #:nodoc: ...@@ -207,7 +207,7 @@ module ActionMailer #:nodoc:
# scores instead of hyphens, so <tt>Content-Transfer-Encoding:</tt> # scores instead of hyphens, so <tt>Content-Transfer-Encoding:</tt>
# becomes <tt>:content_transfer_encoding</tt>. The defaults set by Action Mailer are: # becomes <tt>:content_transfer_encoding</tt>. The defaults set by Action Mailer are:
# * <tt>:mime_version => "1.0"</tt> # * <tt>:mime_version => "1.0"</tt>
# * <tt>:charset => "utf-8",</tt> # * <tt>:charset => "UTF-8",</tt>
# * <tt>:content_type => "text/plain",</tt> # * <tt>:content_type => "text/plain",</tt>
# * <tt>:parts_order => [ "text/plain", "text/enriched", "text/html" ]</tt> # * <tt>:parts_order => [ "text/plain", "text/enriched", "text/html" ]</tt>
# #
...@@ -264,7 +264,7 @@ module ActionMailer #:nodoc: ...@@ -264,7 +264,7 @@ module ActionMailer #:nodoc:
# (i.e. multiple parts are assembled from templates which specify the content type in their # (i.e. multiple parts are assembled from templates which specify the content type in their
# filenames) this variable controls how the parts are ordered. # filenames) this variable controls how the parts are ordered.
class Base < AbstractController::Base class Base < AbstractController::Base
include DeliveryMethods, Quoting include DeliveryMethods
abstract! abstract!
include AbstractController::Logger include AbstractController::Logger
...@@ -286,7 +286,7 @@ class Base < AbstractController::Base ...@@ -286,7 +286,7 @@ class Base < AbstractController::Base
class_attribute :default_params class_attribute :default_params
self.default_params = { self.default_params = {
:mime_version => "1.0", :mime_version => "1.0",
:charset => "utf-8", :charset => "UTF-8",
:content_type => "text/plain", :content_type => "text/plain",
:parts_order => [ "text/plain", "text/enriched", "text/html" ] :parts_order => [ "text/plain", "text/enriched", "text/html" ]
}.freeze }.freeze
...@@ -531,7 +531,7 @@ def mail(headers={}, &block) ...@@ -531,7 +531,7 @@ def mail(headers={}, &block)
# Quote fields # Quote fields
headers[:subject] ||= default_i18n_subject headers[:subject] ||= default_i18n_subject
quote_fields!(headers, charset) set_fields!(headers, charset)
# Render the templates and blocks # Render the templates and blocks
responses, explicit_order = collect_responses_and_parts_order(headers, &block) responses, explicit_order = collect_responses_and_parts_order(headers, &block)
...@@ -577,15 +577,14 @@ def default_i18n_subject #:nodoc: ...@@ -577,15 +577,14 @@ def default_i18n_subject #:nodoc:
I18n.t(:subject, :scope => [:actionmailer, mailer_scope, action_name], :default => action_name.humanize) I18n.t(:subject, :scope => [:actionmailer, mailer_scope, action_name], :default => action_name.humanize)
end end
# TODO: Move this into Mail def set_fields!(headers, charset) #:nodoc:
def quote_fields!(headers, charset) #:nodoc:
m = @_message m = @_message
m.subject ||= quote_if_necessary(headers.delete(:subject), charset) if headers[:subject] m.subject ||= headers.delete(:subject) if headers[:subject]
m.to ||= quote_address_if_necessary(headers.delete(:to), charset) if headers[:to] m.to ||= headers.delete(:to) if headers[:to]
m.from ||= quote_address_if_necessary(headers.delete(:from), charset) if headers[:from] m.from ||= headers.delete(:from) if headers[:from]
m.cc ||= quote_address_if_necessary(headers.delete(:cc), charset) if headers[:cc] m.cc ||= headers.delete(:cc) if headers[:cc]
m.bcc ||= quote_address_if_necessary(headers.delete(:bcc), charset) if headers[:bcc] m.bcc ||= headers.delete(:bcc) if headers[:bcc]
m.reply_to ||= quote_address_if_necessary(headers.delete(:reply_to), charset) if headers[:reply_to] m.reply_to ||= headers.delete(:reply_to) if headers[:reply_to]
end end
def collect_responses_and_parts_order(headers) #:nodoc: def collect_responses_and_parts_order(headers) #:nodoc:
......
...@@ -147,8 +147,8 @@ def normalize_file_hash(params) ...@@ -147,8 +147,8 @@ def normalize_file_hash(params)
def create_mail def create_mail
m = @_message m = @_message
quote_fields!({:subject => subject, :to => recipients, :from => from, set_fields!({:subject => subject, :to => recipients, :from => from,
:bcc => bcc, :cc => cc, :reply_to => reply_to}, charset) :bcc => bcc, :cc => cc, :reply_to => reply_to}, charset)
m.mime_version = mime_version unless mime_version.nil? m.mime_version = mime_version unless mime_version.nil?
m.date = sent_on.to_time rescue sent_on if sent_on m.date = sent_on.to_time rescue sent_on if sent_on
......
...@@ -8,7 +8,7 @@ def initialize(name) ...@@ -8,7 +8,7 @@ def initialize(name)
end end
class TestCase < ActiveSupport::TestCase class TestCase < ActiveSupport::TestCase
include Quoting, TestHelper include TestHelper
setup :initialize_test_deliveries setup :initialize_test_deliveries
setup :set_expected_mail setup :set_expected_mail
...@@ -48,11 +48,11 @@ def set_expected_mail ...@@ -48,11 +48,11 @@ def set_expected_mail
private private
def charset def charset
"utf-8" "UTF-8"
end end
def encode(subject) def encode(subject)
quoted_printable(subject, charset) Mail::Encodings.q_value_encode(subject, charset)
end end
def read_fixture(action) def read_fixture(action)
......
...@@ -105,7 +105,7 @@ def utf8_body(recipient) ...@@ -105,7 +105,7 @@ def utf8_body(recipient)
sent_on Time.local(2004, 12, 12) sent_on Time.local(2004, 12, 12)
cc "Foo áëô îü <extended@example.net>" cc "Foo áëô îü <extended@example.net>"
bcc "Foo áëô îü <extended@example.net>" bcc "Foo áëô îü <extended@example.net>"
charset "utf-8" charset "UTF-8"
body "åœö blah" body "åœö blah"
end end
...@@ -131,7 +131,7 @@ def multipart_with_utf8_subject(recipient) ...@@ -131,7 +131,7 @@ def multipart_with_utf8_subject(recipient)
recipients recipient recipients recipient
subject "Foo áëô îü" subject "Foo áëô îü"
from "test@example.com" from "test@example.com"
charset "utf-8" charset "UTF-8"
part "text/plain" do |p| part "text/plain" do |p|
p.body = "blah" p.body = "blah"
...@@ -316,18 +316,15 @@ def receive(mail) ...@@ -316,18 +316,15 @@ def receive(mail)
end end
class ActionMailerTest < Test::Unit::TestCase class ActionMailerTest < Test::Unit::TestCase
include ActionMailer::Quoting
def encode( text, charset="utf-8" ) def encode( text, charset="UTF-8" )
quoted_printable( text, charset ) Mail::Encodings.q_value_encode( text, charset )
end end
def new_mail( charset="utf-8" ) def new_mail( charset="UTF-8" )
mail = Mail.new mail = Mail.new
mail.charset = charset
mail.mime_version = "1.0" mail.mime_version = "1.0"
if charset
mail.content_type ["text", "plain", { "charset" => charset }]
end
mail mail
end end
...@@ -671,14 +668,14 @@ def test_performs_delivery_via_sendmail ...@@ -671,14 +668,14 @@ def test_performs_delivery_via_sendmail
def test_unquote_quoted_printable_subject def test_unquote_quoted_printable_subject
msg = <<EOF msg = <<EOF
From: me@example.com From: me@example.com
Subject: =?utf-8?Q?testing_testing_=D6=A4?= Subject: =?UTF-8?Q?testing_testing_=D6=A4?=
Content-Type: text/plain; charset=iso-8859-1 Content-Type: text/plain; charset=iso-8859-1
The body The body
EOF EOF
mail = Mail.new(msg) mail = Mail.new(msg)
assert_equal "testing testing \326\244", mail.subject assert_equal "testing testing \326\244", mail.subject
assert_equal "Subject: =?utf-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded assert_equal "Subject: testing\r\n\t=?UTF-8?Q?_testing_=D6=A4=?=\r\n", mail[:subject].encoded
end end
def test_unquote_7bit_subject def test_unquote_7bit_subject
...@@ -719,7 +716,7 @@ def test_unquote_quoted_printable_body ...@@ -719,7 +716,7 @@ def test_unquote_quoted_printable_body
EOF EOF
mail = Mail.new(msg) mail = Mail.new(msg)
assert_equal "The=body", mail.body.to_s.strip assert_equal "The=body", mail.body.to_s.strip
assert_equal "The=3Dbody", mail.body.encoded.strip assert_equal "The=3Dbody=", mail.body.encoded.strip
end end
def test_unquote_base64_body def test_unquote_base64_body
...@@ -740,12 +737,12 @@ def test_extended_headers ...@@ -740,12 +737,12 @@ def test_extended_headers
@recipient = "Grytøyr <test@localhost>" @recipient = "Grytøyr <test@localhost>"
expected = new_mail "iso-8859-1" expected = new_mail "iso-8859-1"
expected.to = quote_address_if_necessary @recipient, "iso-8859-1" expected.to = @recipient
expected.subject = "testing extended headers" expected.subject = "testing extended headers"
expected.body = "Nothing to see here." expected.body = "Nothing to see here."
expected.from = quote_address_if_necessary "Grytøyr <stian1@example.net>", "iso-8859-1" expected.from = "Grytøyr <stian1@example.net>"
expected.cc = quote_address_if_necessary "Grytøyr <stian2@example.net>", "iso-8859-1" expected.cc = "Grytøyr <stian2@example.net>"
expected.bcc = quote_address_if_necessary "Grytøyr <stian3@example.net>", "iso-8859-1" expected.bcc = "Grytøyr <stian3@example.net>"
expected.date = Time.local 2004, 12, 12 expected.date = Time.local 2004, 12, 12
created = nil created = nil
...@@ -774,13 +771,13 @@ def test_extended_headers ...@@ -774,13 +771,13 @@ def test_extended_headers
def test_utf8_body_is_not_quoted def test_utf8_body_is_not_quoted
@recipient = "Foo áëô îü <extended@example.net>" @recipient = "Foo áëô îü <extended@example.net>"
expected = new_mail "utf-8" expected = new_mail "UTF-8"
expected.to = quote_address_if_necessary @recipient, "utf-8" expected.to = @recipient
expected.subject = "testing utf-8 body" expected.subject = "testing UTF-8 body"
expected.body = "åœö blah" expected.body = "åœö blah"
expected.from = quote_address_if_necessary @recipient, "utf-8" expected.from = @recipient
expected.cc = quote_address_if_necessary @recipient, "utf-8" expected.cc = @recipient
expected.bcc = quote_address_if_necessary @recipient, "utf-8" expected.bcc = @recipient
expected.date = Time.local 2004, 12, 12 expected.date = Time.local 2004, 12, 12
created = TestMailer.utf8_body @recipient created = TestMailer.utf8_body @recipient
...@@ -789,18 +786,21 @@ def test_utf8_body_is_not_quoted ...@@ -789,18 +786,21 @@ def test_utf8_body_is_not_quoted
def test_multiple_utf8_recipients def test_multiple_utf8_recipients
@recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"] @recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"]
expected = new_mail "utf-8" expected = new_mail "UTF-8"
expected.to = quote_address_if_necessary @recipient, "utf-8" expected.to = @recipient
expected.subject = "testing utf-8 body" expected.subject = "testing UTF-8 body"
expected.body = "åœö blah" expected.body = "åœö blah"
expected.from = quote_address_if_necessary @recipient.first, "utf-8" expected.from = @recipient.first
expected.cc = quote_address_if_necessary @recipient, "utf-8" expected.cc = @recipient
expected.bcc = quote_address_if_necessary @recipient, "utf-8" expected.bcc = @recipient
expected.date = Time.local 2004, 12, 12 expected.date = Time.local 2004, 12, 12
created = TestMailer.utf8_body @recipient created = TestMailer.utf8_body @recipient
assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>\r/, created.encoded) from_regexp = Regexp.escape('From: Foo =?UTF-8?B?w6HDq8O0?= =?UTF-8?B?IMOuw7w=?=')
assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= <extended@example.net>, \r\n\tExample Recipient <me/, created.encoded) assert_match(/#{from_regexp}/m, created.encoded)
to_regexp = Regexp.escape("To: =?UTF-8?B?Rm9vIMOhw6vDtCDDrsO8?= <extended@example.net>")
assert_match(/#{to_regexp}/m, created.encoded)
end end
def test_receive_decodes_base64_encoded_mail def test_receive_decodes_base64_encoded_mail
...@@ -864,12 +864,19 @@ def test_multipart_with_mime_version ...@@ -864,12 +864,19 @@ def test_multipart_with_mime_version
def test_multipart_with_utf8_subject def test_multipart_with_utf8_subject
mail = TestMailer.multipart_with_utf8_subject(@recipient) mail = TestMailer.multipart_with_utf8_subject(@recipient)
assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded) regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC=?=')
assert_match(/#{regex}/, mail.encoded)
string = "Foo áëô îü"
string.force_encoding('UTF-8') if string.respond_to?(:force_encoding)
assert_match(string, mail.subject.decoded)
end end
def test_implicitly_multipart_with_utf8 def test_implicitly_multipart_with_utf8
mail = TestMailer.implicitly_multipart_with_utf8 mail = TestMailer.implicitly_multipart_with_utf8
assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded) regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC=?=')
assert_match(/#{regex}/, mail.encoded)
string.force_encoding('UTF-8') if string.respond_to?(:force_encoding)
assert_match(string, mail.subject.decoded)
end end
def test_explicitly_multipart_messages def test_explicitly_multipart_messages
...@@ -909,11 +916,11 @@ def test_implicitly_multipart_messages ...@@ -909,11 +916,11 @@ def test_implicitly_multipart_messages
assert_equal "1.0", mail.mime_version.to_s assert_equal "1.0", mail.mime_version.to_s
assert_equal "multipart/alternative", mail.mime_type assert_equal "multipart/alternative", mail.mime_type
assert_equal "text/plain", mail.parts[0].mime_type assert_equal "text/plain", mail.parts[0].mime_type
assert_equal "utf-8", mail.parts[0].charset assert_equal "UTF-8", mail.parts[0].charset
assert_equal "text/html", mail.parts[1].mime_type assert_equal "text/html", mail.parts[1].mime_type
assert_equal "utf-8", mail.parts[1].charset assert_equal "UTF-8", mail.parts[1].charset
assert_equal "application/x-yaml", mail.parts[2].mime_type assert_equal "application/x-yaml", mail.parts[2].mime_type
assert_equal "utf-8", mail.parts[2].charset assert_equal "UTF-8", mail.parts[2].charset
end end
def test_implicitly_multipart_messages_with_custom_order def test_implicitly_multipart_messages_with_custom_order
...@@ -1044,13 +1051,13 @@ def test_multipart_with_template_path_with_dots ...@@ -1044,13 +1051,13 @@ def test_multipart_with_template_path_with_dots
mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient) mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient)
assert_equal 2, mail.parts.length assert_equal 2, mail.parts.length
assert "text/plain", mail.parts[1].mime_type assert "text/plain", mail.parts[1].mime_type
assert "utf-8", mail.parts[1].charset assert "UTF-8", mail.parts[1].charset
end end
def test_custom_content_type_attributes def test_custom_content_type_attributes
mail = TestMailer.custom_content_type_attributes mail = TestMailer.custom_content_type_attributes
assert_match %r{format=flowed}, mail.content_type assert_match %r{format=flowed}, mail.content_type
assert_match %r{charset=utf-8}, mail.content_type assert_match %r{charset=UTF-8}, mail.content_type
end end
def test_return_path_with_create def test_return_path_with_create
......
...@@ -29,13 +29,12 @@ def signed_up_with_url(recipient) ...@@ -29,13 +29,12 @@ def signed_up_with_url(recipient)
end end
class ActionMailerUrlTest < Test::Unit::TestCase class ActionMailerUrlTest < Test::Unit::TestCase
include ActionMailer::Quoting
def encode( text, charset="utf-8" ) def encode( text, charset="UTF-8" )
quoted_printable( text, charset ) quoted_printable( text, charset )
end end
def new_mail( charset="utf-8" ) def new_mail( charset="UTF-8" )
mail = Mail.new mail = Mail.new
mail.mime_version = "1.0" mail.mime_version = "1.0"
if charset if charset
......
...@@ -34,7 +34,7 @@ def test_determine_default_mailer_raises_correct_error ...@@ -34,7 +34,7 @@ def test_determine_default_mailer_raises_correct_error
end end
def test_charset_is_utf_8 def test_charset_is_utf_8
assert_equal "utf-8", charset assert_equal "UTF-8", charset
end end
def test_encode def test_encode
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册