From 8f22be04dc28db45d16877637209bb024436ad11 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Thu, 1 Apr 2010 10:20:08 +1100 Subject: Removing quoting and adding Mail 2.3.5 --- actionmailer/actionmailer.gemspec | 2 +- actionmailer/lib/action_mailer.rb | 1 - actionmailer/lib/action_mailer/quoting.rb | 64 ------------------------------- 3 files changed, 1 insertion(+), 66 deletions(-) delete mode 100644 actionmailer/lib/action_mailer/quoting.rb (limited to 'actionmailer') diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec index 410df0e106..e2724fcadb 100644 --- a/actionmailer/actionmailer.gemspec +++ b/actionmailer/actionmailer.gemspec @@ -20,6 +20,6 @@ Gem::Specification.new do |s| s.has_rdoc = true s.add_dependency('actionpack', version) - s.add_dependency('mail', '~> 2.1.5.3') + s.add_dependency('mail', '~> 2.1.5.5') s.add_dependency('text-format', '~> 1.0.0') end diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 43d73e71b9..46168d9a4a 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -46,7 +46,6 @@ module ActionMailer autoload :DeprecatedApi autoload :MailHelper autoload :OldApi - autoload :Quoting autoload :TestCase autoload :TestHelper end diff --git a/actionmailer/lib/action_mailer/quoting.rb b/actionmailer/lib/action_mailer/quoting.rb deleted file mode 100644 index 2b55c0f0ab..0000000000 --- a/actionmailer/lib/action_mailer/quoting.rb +++ /dev/null @@ -1,64 +0,0 @@ -module ActionMailer - module Quoting #:nodoc: - # TODO extract this into Mail itself. - # - # - # Convert the given text into quoted printable format, with an instruction - # that the text be eventually interpreted in the given charset. - def quoted_printable(text, charset) - text = text.gsub( /[^a-z ]/i ) { quoted_printable_encode($&) }. - gsub( / /, "_" ) - "=?#{charset}?Q?#{text}?=" - end - - # Convert the given character to quoted printable format, taking into - # account multi-byte characters (if executing with $KCODE="u", for instance) - def quoted_printable_encode(character) - result = "" - character.each_byte { |b| result << "=%02X" % b } - result - end - - # A quick-and-dirty regexp for determining whether a string contains any - # characters that need escaping. - if !defined?(CHARS_NEEDING_QUOTING) - CHARS_NEEDING_QUOTING = Regexp.new('[\000-\011\013\014\016-\037\177-\377]', nil, 'n') - end - - # Quote the given text if it contains any "illegal" characters - def quote_if_necessary(text, charset) - text = text.dup.force_encoding(Encoding::ASCII_8BIT) if text.respond_to?(:force_encoding) - - (text =~ CHARS_NEEDING_QUOTING) ? - quoted_printable(text, charset) : - text - end - - # Quote any of the given strings if they contain any "illegal" characters - def quote_any_if_necessary(charset, *args) - args.map { |v| quote_if_necessary(v, charset) } - end - - # Quote the given address if it needs to be. The address may be a - # regular email address, or it can be a phrase followed by an address in - # brackets. The phrase is the only part that will be quoted, and only if - # it needs to be. This allows extended characters to be used in the - # "to", "from", "cc", "bcc" and "reply-to" headers. - def quote_address_if_necessary(address, charset) - if Array === address - address.map { |a| quote_address_if_necessary(a, charset) }.join(", ") - elsif address =~ /^(\S.*)\s+(<.*>)$/ - address = $2 - phrase = quote_if_necessary($1.gsub(/^['"](.*)['"]$/, '\1'), charset) - "\"#{phrase}\" #{address}" - else - address - end - end - - # Quote any of the given addresses, if they need to be. - def quote_any_address_if_necessary(charset, *args) - args.map { |v| quote_address_if_necessary(v, charset) } - end - end -end -- cgit v1.2.3 From dbcf01e6310bf3dc72499beb8f4161fb82143388 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Thu, 8 Apr 2010 12:47:17 +1000 Subject: Removing quoting.rb, upgrade to 2.1.3.6, changing all utf-8 references to UTF-8, updating tests where incorrect encoding --- actionmailer/CHANGELOG | 6 ++ actionmailer/actionmailer.gemspec | 2 +- actionmailer/lib/action_mailer/base.rb | 23 ++++--- actionmailer/lib/action_mailer/old_api.rb | 4 +- actionmailer/lib/action_mailer/test_case.rb | 6 +- actionmailer/test/old_base/mail_service_test.rb | 81 ++++++++++++++----------- actionmailer/test/old_base/url_test.rb | 5 +- actionmailer/test/test_helper_test.rb | 2 +- 8 files changed, 70 insertions(+), 59 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index 605b18d7e9..697e0887ed 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -5,6 +5,12 @@ ActionMailer::Base.register_interceptor calls Mail.register_interceptor 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. diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec index e2724fcadb..852cc704c6 100644 --- a/actionmailer/actionmailer.gemspec +++ b/actionmailer/actionmailer.gemspec @@ -20,6 +20,6 @@ Gem::Specification.new do |s| s.has_rdoc = true 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') end diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index af7255ae4f..5dbe1738a1 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -207,7 +207,7 @@ module ActionMailer #:nodoc: # scores instead of hyphens, so Content-Transfer-Encoding: # becomes :content_transfer_encoding. The defaults set by Action Mailer are: # * :mime_version => "1.0" - # * :charset => "utf-8", + # * :charset => "UTF-8", # * :content_type => "text/plain", # * :parts_order => [ "text/plain", "text/enriched", "text/html" ] # @@ -264,7 +264,7 @@ module ActionMailer #:nodoc: # (i.e. multiple parts are assembled from templates which specify the content type in their # filenames) this variable controls how the parts are ordered. class Base < AbstractController::Base - include DeliveryMethods, Quoting + include DeliveryMethods abstract! include AbstractController::Logger @@ -286,7 +286,7 @@ module ActionMailer #:nodoc: class_attribute :default_params self.default_params = { :mime_version => "1.0", - :charset => "utf-8", + :charset => "UTF-8", :content_type => "text/plain", :parts_order => [ "text/plain", "text/enriched", "text/html" ] }.freeze @@ -531,7 +531,7 @@ module ActionMailer #:nodoc: # Quote fields headers[:subject] ||= default_i18n_subject - quote_fields!(headers, charset) + set_fields!(headers, charset) # Render the templates and blocks responses, explicit_order = collect_responses_and_parts_order(headers, &block) @@ -577,15 +577,14 @@ module ActionMailer #:nodoc: I18n.t(:subject, :scope => [:actionmailer, mailer_scope, action_name], :default => action_name.humanize) end - # TODO: Move this into Mail - def quote_fields!(headers, charset) #:nodoc: + def set_fields!(headers, charset) #:nodoc: m = @_message - m.subject ||= quote_if_necessary(headers.delete(:subject), charset) if headers[:subject] - m.to ||= quote_address_if_necessary(headers.delete(:to), charset) if headers[:to] - m.from ||= quote_address_if_necessary(headers.delete(:from), charset) if headers[:from] - m.cc ||= quote_address_if_necessary(headers.delete(:cc), charset) if headers[:cc] - m.bcc ||= quote_address_if_necessary(headers.delete(:bcc), charset) if headers[:bcc] - m.reply_to ||= quote_address_if_necessary(headers.delete(:reply_to), charset) if headers[:reply_to] + m.subject ||= headers.delete(:subject) if headers[:subject] + m.to ||= headers.delete(:to) if headers[:to] + m.from ||= headers.delete(:from) if headers[:from] + m.cc ||= headers.delete(:cc) if headers[:cc] + m.bcc ||= headers.delete(:bcc) if headers[:bcc] + m.reply_to ||= headers.delete(:reply_to) if headers[:reply_to] end def collect_responses_and_parts_order(headers) #:nodoc: diff --git a/actionmailer/lib/action_mailer/old_api.rb b/actionmailer/lib/action_mailer/old_api.rb index 7c59a8ae50..24c6ec8eda 100644 --- a/actionmailer/lib/action_mailer/old_api.rb +++ b/actionmailer/lib/action_mailer/old_api.rb @@ -147,8 +147,8 @@ module ActionMailer def create_mail m = @_message - quote_fields!({:subject => subject, :to => recipients, :from => from, - :bcc => bcc, :cc => cc, :reply_to => reply_to}, charset) + set_fields!({:subject => subject, :to => recipients, :from => from, + :bcc => bcc, :cc => cc, :reply_to => reply_to}, charset) m.mime_version = mime_version unless mime_version.nil? m.date = sent_on.to_time rescue sent_on if sent_on diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index 7c4033a125..d4874c6dbf 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -8,7 +8,7 @@ module ActionMailer end class TestCase < ActiveSupport::TestCase - include Quoting, TestHelper + include TestHelper setup :initialize_test_deliveries setup :set_expected_mail @@ -48,11 +48,11 @@ module ActionMailer private def charset - "utf-8" + "UTF-8" end def encode(subject) - quoted_printable(subject, charset) + Mail::Encodings.q_value_encode(subject, charset) end def read_fixture(action) diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb index 9eb067554f..b584245cb2 100644 --- a/actionmailer/test/old_base/mail_service_test.rb +++ b/actionmailer/test/old_base/mail_service_test.rb @@ -105,7 +105,7 @@ class TestMailer < ActionMailer::Base sent_on Time.local(2004, 12, 12) cc "Foo áëô îü " bcc "Foo áëô îü " - charset "utf-8" + charset "UTF-8" body "åœö blah" end @@ -131,7 +131,7 @@ class TestMailer < ActionMailer::Base recipients recipient subject "Foo áëô îü" from "test@example.com" - charset "utf-8" + charset "UTF-8" part "text/plain" do |p| p.body = "blah" @@ -316,18 +316,15 @@ class TestMailer < ActionMailer::Base end class ActionMailerTest < Test::Unit::TestCase - include ActionMailer::Quoting - def encode( text, charset="utf-8" ) - quoted_printable( text, charset ) + def encode( text, charset="UTF-8" ) + Mail::Encodings.q_value_encode( text, charset ) end - def new_mail( charset="utf-8" ) + def new_mail( charset="UTF-8" ) mail = Mail.new + mail.charset = charset mail.mime_version = "1.0" - if charset - mail.content_type ["text", "plain", { "charset" => charset }] - end mail end @@ -671,14 +668,14 @@ class ActionMailerTest < Test::Unit::TestCase def test_unquote_quoted_printable_subject msg = <", "iso-8859-1" - expected.cc = quote_address_if_necessary "Grytøyr ", "iso-8859-1" - expected.bcc = quote_address_if_necessary "Grytøyr ", "iso-8859-1" + expected.from = "Grytøyr " + expected.cc = "Grytøyr " + expected.bcc = "Grytøyr " expected.date = Time.local 2004, 12, 12 created = nil @@ -774,13 +771,13 @@ EOF def test_utf8_body_is_not_quoted @recipient = "Foo áëô îü " - expected = new_mail "utf-8" - expected.to = quote_address_if_necessary @recipient, "utf-8" - expected.subject = "testing utf-8 body" + expected = new_mail "UTF-8" + expected.to = @recipient + expected.subject = "testing UTF-8 body" expected.body = "åœö blah" - expected.from = quote_address_if_necessary @recipient, "utf-8" - expected.cc = quote_address_if_necessary @recipient, "utf-8" - expected.bcc = quote_address_if_necessary @recipient, "utf-8" + expected.from = @recipient + expected.cc = @recipient + expected.bcc = @recipient expected.date = Time.local 2004, 12, 12 created = TestMailer.utf8_body @recipient @@ -789,18 +786,21 @@ EOF def test_multiple_utf8_recipients @recipient = ["\"Foo áëô îü\" ", "\"Example Recipient\" "] - expected = new_mail "utf-8" - expected.to = quote_address_if_necessary @recipient, "utf-8" - expected.subject = "testing utf-8 body" + expected = new_mail "UTF-8" + expected.to = @recipient + expected.subject = "testing UTF-8 body" expected.body = "åœö blah" - expected.from = quote_address_if_necessary @recipient.first, "utf-8" - expected.cc = quote_address_if_necessary @recipient, "utf-8" - expected.bcc = quote_address_if_necessary @recipient, "utf-8" + expected.from = @recipient.first + expected.cc = @recipient + expected.bcc = @recipient expected.date = Time.local 2004, 12, 12 created = TestMailer.utf8_body @recipient - assert_match(/\nFrom: =\?utf-8\?Q\?Foo_.*?\?= \r/, created.encoded) - assert_match(/\nTo: =\?utf-8\?Q\?Foo_.*?\?= , \r\n\tExample Recipient ") + assert_match(/#{to_regexp}/m, created.encoded) end def test_receive_decodes_base64_encoded_mail @@ -864,12 +864,19 @@ EOF def test_multipart_with_utf8_subject 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 def test_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 def test_explicitly_multipart_messages @@ -909,11 +916,11 @@ EOF assert_equal "1.0", mail.mime_version.to_s assert_equal "multipart/alternative", mail.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 "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 "utf-8", mail.parts[2].charset + assert_equal "UTF-8", mail.parts[2].charset end def test_implicitly_multipart_messages_with_custom_order @@ -1044,13 +1051,13 @@ EOF mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient) assert_equal 2, mail.parts.length assert "text/plain", mail.parts[1].mime_type - assert "utf-8", mail.parts[1].charset + assert "UTF-8", mail.parts[1].charset end def test_custom_content_type_attributes mail = TestMailer.custom_content_type_attributes 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 def test_return_path_with_create diff --git a/actionmailer/test/old_base/url_test.rb b/actionmailer/test/old_base/url_test.rb index 17b383cc2a..6895fb230e 100644 --- a/actionmailer/test/old_base/url_test.rb +++ b/actionmailer/test/old_base/url_test.rb @@ -29,13 +29,12 @@ class UrlTestMailer < ActionMailer::Base end class ActionMailerUrlTest < Test::Unit::TestCase - include ActionMailer::Quoting - def encode( text, charset="utf-8" ) + def encode( text, charset="UTF-8" ) quoted_printable( text, charset ) end - def new_mail( charset="utf-8" ) + def new_mail( charset="UTF-8" ) mail = Mail.new mail.mime_version = "1.0" if charset diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb index 3a38a91c28..c23a9e7e3c 100644 --- a/actionmailer/test/test_helper_test.rb +++ b/actionmailer/test/test_helper_test.rb @@ -34,7 +34,7 @@ class TestHelperMailerTest < ActionMailer::TestCase end def test_charset_is_utf_8 - assert_equal "utf-8", charset + assert_equal "UTF-8", charset end def test_encode -- cgit v1.2.3 From 6c6bef245a7b636cbd6a0162cc5061d8c040aadb Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Thu, 8 Apr 2010 20:40:43 +1000 Subject: Fixing up some bad test cases --- actionmailer/test/old_base/mail_service_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb index b584245cb2..9cf01854c5 100644 --- a/actionmailer/test/old_base/mail_service_test.rb +++ b/actionmailer/test/old_base/mail_service_test.rb @@ -567,7 +567,6 @@ class ActionMailerTest < Test::Unit::TestCase def test_iso_charset TestMailer.delivery_method = :test - expected = new_mail( "iso-8859-1" ) expected.to = @recipient expected.subject = encode "testing isø charsets", "iso-8859-1" @@ -868,15 +867,16 @@ EOF assert_match(/#{regex}/, mail.encoded) string = "Foo áëô îü" string.force_encoding('UTF-8') if string.respond_to?(:force_encoding) - assert_match(string, mail.subject.decoded) + assert_match(string, mail.subject) end def test_implicitly_multipart_with_utf8 mail = TestMailer.implicitly_multipart_with_utf8 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) + assert_match(string, mail.subject) end def test_explicitly_multipart_messages -- cgit v1.2.3 From e157a3d2224253303719c92b262413dfc735b6de Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Thu, 8 Apr 2010 21:11:42 +1000 Subject: Added explict setting of charset in set_fields! method to make sure Mail has the user defined default --- actionmailer/CHANGELOG | 2 ++ actionmailer/lib/action_mailer/base.rb | 1 + 2 files changed, 3 insertions(+) (limited to 'actionmailer') diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index 697e0887ed..8a064829c7 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -5,6 +5,8 @@ ActionMailer::Base.register_interceptor calls Mail.register_interceptor ActionMailer::Base.register_observer calls Mail.register_observer +* Added explict setting of charset in set_fields! method to make sure Mail has the user defined default + * 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. diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 5dbe1738a1..c96ceb72f9 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -579,6 +579,7 @@ module ActionMailer #:nodoc: def set_fields!(headers, charset) #:nodoc: m = @_message + m.charset = charset m.subject ||= headers.delete(:subject) if headers[:subject] m.to ||= headers.delete(:to) if headers[:to] m.from ||= headers.delete(:from) if headers[:from] -- cgit v1.2.3 From 03dd8f79171fb593d14c43be8ddf520d76b1f62f Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Thu, 8 Apr 2010 21:12:45 +1000 Subject: Mail::Part now no longer has nil as a default charset, it is always set to something, and defaults to UTF-8 --- actionmailer/CHANGELOG | 2 ++ actionmailer/test/old_base/mail_service_test.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'actionmailer') diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index 8a064829c7..dbda0d87b2 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -5,6 +5,8 @@ ActionMailer::Base.register_interceptor calls Mail.register_interceptor ActionMailer::Base.register_observer calls Mail.register_observer +* Mail::Part now no longer has nil as a default charset, it is always set to something, and defaults to UTF-8 + * Added explict setting of charset in set_fields! method to make sure Mail has the user defined default * Removed quoting.rb and refactored for Mail to take responsibility of all quoting and auto encoding requirements for the header. diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb index 9cf01854c5..b68e7fcbac 100644 --- a/actionmailer/test/old_base/mail_service_test.rb +++ b/actionmailer/test/old_base/mail_service_test.rb @@ -355,7 +355,7 @@ class ActionMailerTest < Test::Unit::TestCase assert_equal "multipart/mixed", created.mime_type assert_equal "multipart/alternative", created.parts[0].mime_type assert_equal "bar", created.parts[0].header['foo'].to_s - assert_nil created.parts[0].charset + assert_not_nil created.parts[0].charset assert_equal "text/plain", created.parts[0].parts[0].mime_type assert_equal "text/html", created.parts[0].parts[1].mime_type assert_equal "application/octet-stream", created.parts[1].mime_type -- cgit v1.2.3 From a9e918f40e1b6da5d43d6d372070bab61854b3a2 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Fri, 9 Apr 2010 19:45:59 +1000 Subject: Don't need no quoting test, done in mail --- actionmailer/test/quoting_test.rb | 106 -------------------------------------- 1 file changed, 106 deletions(-) delete mode 100644 actionmailer/test/quoting_test.rb (limited to 'actionmailer') diff --git a/actionmailer/test/quoting_test.rb b/actionmailer/test/quoting_test.rb deleted file mode 100644 index 7640f4b086..0000000000 --- a/actionmailer/test/quoting_test.rb +++ /dev/null @@ -1,106 +0,0 @@ -# encoding: utf-8 -require 'abstract_unit' -require 'tempfile' - -class QuotingTest < Test::Unit::TestCase - # Move some tests from TMAIL here - def test_unquote_quoted_printable - a ="=?ISO-8859-1?Q?[166417]_Bekr=E6ftelse_fra_Rejsefeber?=" - b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8') - assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b - end - - def test_unquote_base64 - a ="=?ISO-8859-1?B?WzE2NjQxN10gQmVrcuZmdGVsc2UgZnJhIFJlanNlZmViZXI=?=" - b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8') - assert_equal "[166417] Bekr\303\246ftelse fra Rejsefeber", b - end - - def test_unquote_without_charset - a ="[166417]_Bekr=E6ftelse_fra_Rejsefeber" - b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8') - assert_equal "[166417]_Bekr=E6ftelse_fra_Rejsefeber", b - end - - def test_unqoute_multiple - a ="=?utf-8?q?Re=3A_=5B12=5D_=23137=3A_Inkonsistente_verwendung_von_=22Hin?==?utf-8?b?enVmw7xnZW4i?=" - b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8') - assert_equal "Re: [12] #137: Inkonsistente verwendung von \"Hinzuf\303\274gen\"", b - end - - def test_unqoute_in_the_middle - a ="Re: Photos =?ISO-8859-1?Q?Brosch=FCre_Rand?=" - b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8') - assert_equal "Re: Photos Brosch\303\274re Rand", b - end - - def test_unqoute_iso - a ="=?ISO-8859-1?Q?Brosch=FCre_Rand?=" - b = Mail::Encodings.unquote_and_convert_to(a, 'iso-8859-1') - expected = "Brosch\374re Rand" - expected.force_encoding 'iso-8859-1' if expected.respond_to?(:force_encoding) - assert_equal expected, b - end - - def test_quote_multibyte_chars - original = "\303\246 \303\270 and \303\245" - original.force_encoding('ASCII-8BIT') if original.respond_to?(:force_encoding) - - result = execute_in_sandbox(<<-CODE) - $:.unshift(File.dirname(__FILE__) + "/../lib/") - if RUBY_VERSION < '1.9' - $KCODE = 'u' - end - require 'action_mailer/quoting' - include ActionMailer::Quoting - quoted_printable(#{original.inspect}, "UTF-8") - CODE - - unquoted = Mail::Encodings.unquote_and_convert_to(result, nil) - - unquoted.force_encoding(Encoding::ASCII_8BIT) if unquoted.respond_to?(:force_encoding) - original.force_encoding(Encoding::ASCII_8BIT) if original.respond_to?(:force_encoding) - - assert_equal unquoted, original - end - - - # test an email that has been created using \r\n newlines, instead of - # \n newlines. - def test_email_quoted_with_0d0a - mail = Mail.new(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_quoted_with_0d0a")) - # CHANGED: subject returns an object now - # assert_match %r{Elapsed time}, mail.body - assert_match %r{Elapsed time}, mail.body.to_s - end - - def test_email_with_partially_quoted_subject - mail = Mail.new(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_partially_quoted_subject")) - # CHANGED: subject returns an object now - # assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject - assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject - end - - private - # This whole thing *could* be much simpler, but I don't think Tempfile, - # popen and others exist on all platforms (like Windows). - def execute_in_sandbox(code) - test_name = "#{File.dirname(__FILE__)}/am-quoting-test.#{$$}.rb" - res_name = "#{File.dirname(__FILE__)}/am-quoting-test.#{$$}.out" - - File.open(test_name, "w+") do |file| - file.write(<<-CODE) - block = Proc.new do - #{code} - end - puts block.call - CODE - end - - system("ruby #{test_name} > #{res_name}") or raise "could not run test in sandbox" - File.read(res_name).chomp - ensure - File.delete(test_name) rescue nil - File.delete(res_name) rescue nil - end -end -- cgit v1.2.3 From fd9ee49f38bbc845fe1ac61d6e85a9304bdfb902 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Fri, 9 Apr 2010 19:46:13 +1000 Subject: Moved test of QP into mail --- actionmailer/test/test_helper_test.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb index c23a9e7e3c..440fb868c8 100644 --- a/actionmailer/test/test_helper_test.rb +++ b/actionmailer/test/test_helper_test.rb @@ -37,10 +37,6 @@ class TestHelperMailerTest < ActionMailer::TestCase assert_equal "UTF-8", charset end - def test_encode - assert_equal "=?utf-8?Q?=0Aasdf=0A?=", encode("\nasdf\n") - end - def test_assert_emails assert_nothing_raised do assert_emails 1 do -- cgit v1.2.3 From bd89c391e81c82f72508118a1f6d19274463c182 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sat, 10 Apr 2010 16:11:46 +1000 Subject: Cleaning up expectations from the new way mail does it --- actionmailer/test/old_base/mail_service_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb index b68e7fcbac..32ed9fc870 100644 --- a/actionmailer/test/old_base/mail_service_test.rb +++ b/actionmailer/test/old_base/mail_service_test.rb @@ -674,7 +674,7 @@ The body EOF mail = Mail.new(msg) assert_equal "testing testing \326\244", mail.subject - assert_equal "Subject: testing\r\n\t=?UTF-8?Q?_testing_=D6=A4=?=\r\n", mail[:subject].encoded + assert_equal "Subject: testing =?UTF-8?Q?_testing_=D6=A4=?=\r\n", mail[:subject].encoded end def test_unquote_7bit_subject @@ -863,7 +863,7 @@ EOF def test_multipart_with_utf8_subject mail = TestMailer.multipart_with_utf8_subject(@recipient) - regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC=?=') + regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=') assert_match(/#{regex}/, mail.encoded) string = "Foo áëô îü" string.force_encoding('UTF-8') if string.respond_to?(:force_encoding) @@ -872,7 +872,7 @@ EOF def test_implicitly_multipart_with_utf8 mail = TestMailer.implicitly_multipart_with_utf8 - regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC=?=') + regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=') assert_match(/#{regex}/, mail.encoded) string = "Foo áëô îü" string.force_encoding('UTF-8') if string.respond_to?(:force_encoding) -- cgit v1.2.3 From 2a793fa2a89cadb6b5a98cde6118d37e4f030c74 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 11 Apr 2010 17:58:01 +1000 Subject: New mail is more intelligent on encoding and decoding --- actionmailer/test/old_base/mail_service_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionmailer') diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb index 32ed9fc870..db2db59cc7 100644 --- a/actionmailer/test/old_base/mail_service_test.rb +++ b/actionmailer/test/old_base/mail_service_test.rb @@ -674,7 +674,7 @@ The body EOF mail = Mail.new(msg) assert_equal "testing testing \326\244", mail.subject - assert_equal "Subject: testing =?UTF-8?Q?_testing_=D6=A4=?=\r\n", mail[:subject].encoded + assert_equal "Subject: testing testing =?UTF-8?Q?_=D6=A4=?=\r\n", mail[:subject].encoded end def test_unquote_7bit_subject @@ -863,7 +863,7 @@ EOF def test_multipart_with_utf8_subject mail = TestMailer.multipart_with_utf8_subject(@recipient) - regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=') + regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=') assert_match(/#{regex}/, mail.encoded) string = "Foo áëô îü" string.force_encoding('UTF-8') if string.respond_to?(:force_encoding) @@ -872,7 +872,7 @@ EOF def test_implicitly_multipart_with_utf8 mail = TestMailer.implicitly_multipart_with_utf8 - regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=') + regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=') assert_match(/#{regex}/, mail.encoded) string = "Foo áëô îü" string.force_encoding('UTF-8') if string.respond_to?(:force_encoding) -- cgit v1.2.3 From fc5d81714534636055f347ff19c178bd2c979df3 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 11 Apr 2010 17:58:43 +1000 Subject: Updating actionmailer to Mail version 2.2.0 --- actionmailer/actionmailer.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer') diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec index 852cc704c6..01a886c5ee 100644 --- a/actionmailer/actionmailer.gemspec +++ b/actionmailer/actionmailer.gemspec @@ -20,6 +20,6 @@ Gem::Specification.new do |s| s.has_rdoc = true s.add_dependency('actionpack', version) - s.add_dependency('mail', '~> 2.1.5.6') + s.add_dependency('mail', '~> 2.2.0') s.add_dependency('text-format', '~> 1.0.0') end -- cgit v1.2.3 From dd02090d762bfbb8fdada60142e35247797f32c7 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 11 Apr 2010 18:06:30 +1000 Subject: Updating changelog for Mail 2.2.0 --- actionmailer/CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionmailer') diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index dbda0d87b2..c1b659a9f5 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -1,3 +1,7 @@ +* Removed all quoting.rb type files from ActionMailer and put Mail 2.2.0 in instead [ML] + +* Lot of updates to various test cases that now work better with the new Mail and so have different expectations + *Rails 3.0.0 [beta 2] (April 1st, 2010)* * Added interceptors and observers from Mail [ML] -- cgit v1.2.3