Skip to content
Browse files

Merge branch 'master' of github.com:mikel/rails

  • Loading branch information...
2 parents 6589976 + 74a5889 commit 4af2bbc6b446726b7174d06b5bffbaba82906cbb José Valim and Mikel Lindsaar committed
Showing with 36 additions and 18 deletions.
  1. +22 −9 actionmailer/lib/action_mailer/base.rb
  2. +14 −9 actionmailer/test/base_test.rb
View
31 actionmailer/lib/action_mailer/base.rb
@@ -50,7 +50,7 @@ module ActionMailer #:nodoc:
#
# The mail method, if not passed a block, will inspect your views and send all the views with
# the same name as the method, so the above action would send the +welcome.plain.erb+ view file
- # as well as the +welcome.html.erb+ view file in a +multipart/alternate+ email.
+ # as well as the +welcome.html.erb+ view file in a +multipart/alternative+ email.
#
# If you want to explicitly render only certain templates, pass a block:
#
@@ -177,7 +177,7 @@ module ActionMailer #:nodoc:
#
# Which will (if it had both a <tt>.text.erb</tt> and <tt>.html.erb</tt> tempalte in the view
# directory), send a complete <tt>multipart/mixed</tt> email with two parts, the first part being
- # a <tt>multipart/alternate</tt> with the text and HTML email parts inside, and the second being
+ # a <tt>multipart/alternative</tt> with the text and HTML email parts inside, and the second being
# a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book with the filename
# +free_book.pdf+.
#
@@ -456,7 +456,7 @@ def attachments
# format.html { render :text => "<h1>Hello Mikel!</h1>" }
# end
#
- # Which will render a <tt>multipart/alternate</tt> email with <tt>text/plain</tt> and
+ # Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
# <tt>text/html</tt> parts.
#
# The block syntax also allows you to customize the part headers if desired:
@@ -484,10 +484,11 @@ def mail(headers={}, &block)
# Render the templates and blocks
responses, sort_order = collect_responses_and_sort_order(headers, &block)
- content_type ||= create_parts_from_responses(m, responses, charset)
+
+ create_parts_from_responses(m, responses, charset)
# Tidy up content type, charset, mime version and sort order
- m.content_type = content_type
+ m.content_type = set_content_type(m, content_type)
m.charset = charset
m.mime_version = mime_version
sort_order = headers[:parts_order] || sort_order || self.class.default_implicit_parts_order.dup
@@ -504,6 +505,20 @@ def mail(headers={}, &block)
protected
+ def set_content_type(m, user_content_type)
+ params = m.content_type_parameters || {}
+ case
+ when user_content_type.present?
+ user_content_type
+ when m.has_attachments?
+ ["multipart", "mixed", params]
+ when m.multipart?
+ ["multipart", "alternative", params]
+ else
+ self.class.default_content_type.dup
+ end
+ end
+
def default_subject #:nodoc:
mailer_scope = self.class.mailer_name.gsub('/', '.')
I18n.t(:subject, :scope => [:actionmailer, mailer_scope, action_name], :default => action_name.humanize)
@@ -563,16 +578,14 @@ def create_parts_from_responses(m, responses, charset) #:nodoc:
headers = responses[0]
headers.each { |k,v| m[k] = v }
return responses[0][:content_type]
- elsif responses.size > 1 && m.has_attachments?
+ elsif responses.size > 1 && m.has_attachments?
container = Mail::Part.new
- container.content_type = "multipart/alternate"
+ container.content_type = "multipart/alternative"
responses.each { |r| insert_part(container, r, charset) }
m.add_part(container)
else
responses.each { |r| insert_part(m, r, charset) }
end
-
- m.has_attachments? ? "multipart/mixed" : "multipart/alternate"
end
def insert_part(container, response, charset) #:nodoc:
View
23 actionmailer/test/base_test.rb
@@ -207,7 +207,7 @@ def custom_block(include_html=false)
test "implicit multipart" do
email = BaseMailer.implicit_multipart.deliver
assert_equal(2, email.parts.size)
- assert_equal("multipart/alternate", email.mime_type)
+ assert_equal("multipart/alternative", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("TEXT Implicit Multipart", email.parts[0].body.encoded)
assert_equal("text/html", email.parts[1].mime_type)
@@ -230,7 +230,7 @@ def custom_block(include_html=false)
test "implicit multipart with attachments creates nested parts" do
email = BaseMailer.implicit_multipart(:attachments => true).deliver
assert_equal("application/pdf", email.parts[0].mime_type)
- assert_equal("multipart/alternate", email.parts[1].mime_type)
+ assert_equal("multipart/alternative", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[0].mime_type)
assert_equal("TEXT Implicit Multipart", email.parts[1].parts[0].body.encoded)
assert_equal("text/html", email.parts[1].parts[1].mime_type)
@@ -242,7 +242,7 @@ def custom_block(include_html=false)
swap BaseMailer, :default_implicit_parts_order => order do
email = BaseMailer.implicit_multipart(:attachments => true).deliver
assert_equal("application/pdf", email.parts[0].mime_type)
- assert_equal("multipart/alternate", email.parts[1].mime_type)
+ assert_equal("multipart/alternative", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[1].mime_type)
assert_equal("text/html", email.parts[1].parts[0].mime_type)
end
@@ -251,7 +251,7 @@ def custom_block(include_html=false)
test "implicit multipart with default locale" do
email = BaseMailer.implicit_with_locale.deliver
assert_equal(2, email.parts.size)
- assert_equal("multipart/alternate", email.mime_type)
+ assert_equal("multipart/alternative", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("Implicit with locale TEXT", email.parts[0].body.encoded)
assert_equal("text/html", email.parts[1].mime_type)
@@ -262,7 +262,7 @@ def custom_block(include_html=false)
swap I18n, :locale => :pl do
email = BaseMailer.implicit_with_locale.deliver
assert_equal(2, email.parts.size)
- assert_equal("multipart/alternate", email.mime_type)
+ assert_equal("multipart/alternative", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("Implicit with locale PL TEXT", email.parts[0].body.encoded)
assert_equal("text/html", email.parts[1].mime_type)
@@ -294,7 +294,7 @@ def custom_block(include_html=false)
test "explicit multipart" do
email = BaseMailer.explicit_multipart.deliver
assert_equal(2, email.parts.size)
- assert_equal("multipart/alternate", email.mime_type)
+ assert_equal("multipart/alternative", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("TEXT Explicit Multipart", email.parts[0].body.encoded)
assert_equal("text/html", email.parts[1].mime_type)
@@ -317,7 +317,7 @@ def custom_block(include_html=false)
test "explicit multipart with attachments creates nested parts" do
email = BaseMailer.explicit_multipart(:attachments => true).deliver
assert_equal("application/pdf", email.parts[0].mime_type)
- assert_equal("multipart/alternate", email.parts[1].mime_type)
+ assert_equal("multipart/alternative", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[0].mime_type)
assert_equal("TEXT Explicit Multipart", email.parts[1].parts[0].body.encoded)
assert_equal("text/html", email.parts[1].parts[1].mime_type)
@@ -327,7 +327,7 @@ def custom_block(include_html=false)
test "explicit multipart with templates" do
email = BaseMailer.explicit_multipart_templates.deliver
assert_equal(2, email.parts.size)
- assert_equal("multipart/alternate", email.mime_type)
+ assert_equal("multipart/alternative", email.mime_type)
assert_equal("text/html", email.parts[0].mime_type)
assert_equal("HTML Explicit Multipart Templates", email.parts[0].body.encoded)
assert_equal("text/plain", email.parts[1].mime_type)
@@ -337,7 +337,7 @@ def custom_block(include_html=false)
test "explicit multipart with any" do
email = BaseMailer.explicit_multipart_with_any.deliver
assert_equal(2, email.parts.size)
- assert_equal("multipart/alternate", email.mime_type)
+ assert_equal("multipart/alternative", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("Format with any!", email.parts[0].body.encoded)
assert_equal("text/html", email.parts[1].mime_type)
@@ -394,6 +394,11 @@ def custom_block(include_html=false)
BaseMailer.expects(:welcome).returns(mail)
BaseMailer.welcome.deliver
end
+
+ test "explicit multipart should be multipart" do
+ mail = BaseMailer.explicit_multipart
+ assert_not_nil(mail.content_type_parameters[:boundary])
+ end
protected

0 comments on commit 4af2bbc

Please sign in to comment.
Something went wrong with that request. Please try again.