Permalink
Browse files

Move set_fields! to the old API module.

  • Loading branch information...
1 parent e5f392c commit b5f9a9fce316e96ffb9ab3a69e9311f8b1e56fde @josevalim josevalim committed Apr 12, 2010
Showing with 28 additions and 28 deletions.
  1. +16 −27 actionmailer/lib/action_mailer/base.rb
  2. +12 −1 actionmailer/lib/action_mailer/old_api.rb
View
43 actionmailer/lib/action_mailer/base.rb
@@ -525,19 +525,25 @@ def mail(headers={}, &block)
content_type = headers[:content_type]
parts_order = headers[:parts_order]
- # Merge defaults from class
+ # Handle defaults
headers = headers.reverse_merge(self.class.default)
- charset = headers.delete(:charset)
-
- # Quote fields
headers[:subject] ||= default_i18n_subject
- set_fields!(headers, charset)
+
+ # Apply charset at the beginning so all fields are properly quoted
+ m.charset = charset = headers[:charset]
@kuahyeow
kuahyeow Mar 13, 2012

Note : In Rails 3.1.X if you are seeing "DEPRECATION WARNING: charset() is deprecated and will be removed in future versions.", it's probably caused by this line, in conjunction with https://github.com/rails/rails/blob/3-1-stable/actionmailer/lib/action_mailer/adv_attr_accessor.rb being deprecated.

+
+ # Set configure delivery behavior
+ wrap_delivery_behavior!(headers.delete(:delivery_method))
+
+ # Assign all headers except parts_order, content_type and body
+ assignable = headers.except(:parts_order, :content_type, :body)
+ assignable.each { |k, v| m[k] = v }
# Render the templates and blocks
responses, explicit_order = collect_responses_and_parts_order(headers, &block)
- create_parts_from_responses(m, responses, charset)
+ create_parts_from_responses(m, responses)
- # Finally setup content type and parts order
+ # Setup content type, reapply charset and handle parts order
m.content_type = set_content_type(m, content_type, headers[:content_type])
m.charset = charset
@@ -547,12 +553,6 @@ def mail(headers={}, &block)
m.body.sort_parts!
end
- # Set configure delivery behavior
- wrap_delivery_behavior!(headers.delete(:delivery_method))
-
- # Remove any missing configuration header and assign all others
- headers.except!(:parts_order, :content_type)
- headers.each { |k, v| m[k] = v }
m
end
@@ -577,17 +577,6 @@ def default_i18n_subject #:nodoc:
I18n.t(:subject, :scope => [:actionmailer, mailer_scope, action_name], :default => action_name.humanize)
end
- 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]
- 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:
responses, parts_order = [], nil
@@ -630,16 +619,16 @@ def each_template(paths, name, &block) #:nodoc:
end
end
- def create_parts_from_responses(m, responses, charset) #:nodoc:
+ def create_parts_from_responses(m, responses) #:nodoc:
if responses.size == 1 && !m.has_attachments?
responses[0].each { |k,v| m[k] = v }
elsif responses.size > 1 && m.has_attachments?
container = Mail::Part.new
container.content_type = "multipart/alternative"
- responses.each { |r| insert_part(container, r, charset) }
+ responses.each { |r| insert_part(container, r, m.charset) }
m.add_part(container)
else
- responses.each { |r| insert_part(m, r, charset) }
+ responses.each { |r| insert_part(m, r, m.charset) }
end
end
View
13 actionmailer/lib/action_mailer/old_api.rb
@@ -143,7 +143,7 @@ def normalize_file_hash(params)
{ :content_type => content_type,
:content_disposition => content_disposition }.merge(params)
end
-
+
def create_mail
m = @_message
@@ -230,6 +230,17 @@ def create_inline_part(body, mime_type=nil)
)
end
+ 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]
+ 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 split_content_type(ct)
ct.to_s.split("/")
end

0 comments on commit b5f9a9f

Please sign in to comment.