diff options
author | wycats <wycats@gmail.com> | 2010-04-11 19:20:39 -0700 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-04-11 19:20:39 -0700 |
commit | 59c6082d9867572352e2ac2070d5aa9590132ef8 (patch) | |
tree | e9211dd3d0699452e623309a612a3be5efba0f0e /actionmailer/lib | |
parent | ecf039fc05ac32b7a8cbd005dd4723d7eadc61c0 (diff) | |
parent | dd02090d762bfbb8fdada60142e35247797f32c7 (diff) | |
download | rails-59c6082d9867572352e2ac2070d5aa9590132ef8.tar.gz rails-59c6082d9867572352e2ac2070d5aa9590132ef8.tar.bz2 rails-59c6082d9867572352e2ac2070d5aa9590132ef8.zip |
Merge remote branch 'mikel/master'
Diffstat (limited to 'actionmailer/lib')
-rw-r--r-- | actionmailer/lib/action_mailer.rb | 1 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 24 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/old_api.rb | 4 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/quoting.rb | 64 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 6 |
5 files changed, 17 insertions, 82 deletions
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/base.rb b/actionmailer/lib/action_mailer/base.rb index af7255ae4f..c96ceb72f9 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 <tt>Content-Transfer-Encoding:</tt> # becomes <tt>:content_transfer_encoding</tt>. The defaults set by Action Mailer are: # * <tt>:mime_version => "1.0"</tt> - # * <tt>:charset => "utf-8",</tt> + # * <tt>:charset => "UTF-8",</tt> # * <tt>:content_type => "text/plain",</tt> # * <tt>:parts_order => [ "text/plain", "text/enriched", "text/html" ]</tt> # @@ -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,15 @@ 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.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] + 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/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 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) |