mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Multipart messages specify a MIME-Version header automatically #2003 [John Long]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2038 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
ae1e85200e
commit
dca4d4e86d
3 changed files with 41 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Multipart messages specify a MIME-Version header automatically #2003 [John Long]
|
||||
|
||||
* Add a unified render method to ActionMailer (delegates to ActionView::Base#render)
|
||||
|
||||
* Move mailer initialization to a separate (overridable) method, so that subclasses may alter the various defaults #1727
|
||||
|
|
|
@ -110,6 +110,9 @@ module ActionMailer #:nodoc:
|
|||
# pick a different charset from inside a method with <tt>@charset</tt>.
|
||||
# * <tt>default_content_type</tt> - The default content type used for main part of the message. Defaults to "text/plain". You
|
||||
# can also pick a different content type from inside a method with <tt>@content_type</tt>.
|
||||
# * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to nil. You
|
||||
# can also pick a different value from inside a method with <tt>@mime_version</tt>. When multipart messages are in
|
||||
# use, <tt>@mime_version</tt> will be set to "1.0" if it is not set inside a method.
|
||||
# * <tt>default_implicit_parts_order</tt> - When a message is built implicitly (i.e. multiple parts are assemble from templates
|
||||
# which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to
|
||||
# ["text/html", "text/enriched", "text/plain"]. Items that appear first in the array have higher priority in the mail client
|
||||
|
@ -151,12 +154,15 @@ module ActionMailer #:nodoc:
|
|||
@@default_content_type = "text/plain"
|
||||
cattr_accessor :default_content_type
|
||||
|
||||
@@default_mime_version = nil
|
||||
cattr_accessor :default_mime_version
|
||||
|
||||
@@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
|
||||
cattr_accessor :default_implicit_parts_order
|
||||
|
||||
adv_attr_accessor :recipients, :subject, :body, :from, :sent_on, :headers,
|
||||
:bcc, :cc, :charset, :content_type, :implicit_parts_order,
|
||||
:template, :mailer_name
|
||||
:template, :mailer_name, :mime_version
|
||||
|
||||
attr_reader :mail
|
||||
|
||||
|
@ -206,7 +212,8 @@ module ActionMailer #:nodoc:
|
|||
unless String === @body
|
||||
# First, we look to see if there are any likely templates that match,
|
||||
# which include the content-type in their file name (i.e.,
|
||||
# "the_template_file.text.html.rhtml", etc.).
|
||||
# "the_template_file.text.html.rhtml", etc.). Only do this if parts
|
||||
# have not already been specified manually.
|
||||
if @parts.empty?
|
||||
templates = Dir.glob("#{template_path}/#{@template}.*")
|
||||
templates.each do |path|
|
||||
|
@ -239,6 +246,10 @@ module ActionMailer #:nodoc:
|
|||
end
|
||||
end
|
||||
|
||||
# If this is a multipart e-mail add the mime_version if it is not
|
||||
# already set.
|
||||
@mime_version ||= "1.0" if !@parts.empty?
|
||||
|
||||
# build the mail object itself
|
||||
@mail = create_mail
|
||||
end
|
||||
|
@ -273,6 +284,7 @@ module ActionMailer #:nodoc:
|
|||
@parts = []
|
||||
@headers = {}
|
||||
@body = {}
|
||||
@mime_version = @@default_mime_version.dup if @@default_mime_version
|
||||
end
|
||||
|
||||
def render_message(method_name, body)
|
||||
|
@ -329,6 +341,7 @@ module ActionMailer #:nodoc:
|
|||
m.bcc = quote_address_if_necessary(bcc, charset) unless bcc.nil?
|
||||
m.cc = quote_address_if_necessary(cc, charset) unless cc.nil?
|
||||
|
||||
m.mime_version = mime_version unless mime_version.nil?
|
||||
m.date = sent_on.to_time rescue sent_on if sent_on
|
||||
headers.each { |k, v| m[k] = v }
|
||||
|
||||
|
|
|
@ -94,6 +94,23 @@ class TestMailer < ActionMailer::Base
|
|||
@charset = "utf-8"
|
||||
end
|
||||
|
||||
def multipart_with_mime_version(recipient)
|
||||
recipients recipient
|
||||
subject "multipart with mime_version"
|
||||
from "test@example.com"
|
||||
sent_on Time.local(2004, 12, 12)
|
||||
mime_version "1.1"
|
||||
content_type "multipart/alternative"
|
||||
|
||||
part "text/plain" do |p|
|
||||
p.body = "blah"
|
||||
end
|
||||
|
||||
part "text/html" do |p|
|
||||
p.body = "<b>blah</b>"
|
||||
end
|
||||
end
|
||||
|
||||
def explicitly_multipart_example(recipient, ct=nil)
|
||||
recipients recipient
|
||||
subject "multipart example"
|
||||
|
@ -239,6 +256,7 @@ class ActionMailerTest < Test::Unit::TestCase
|
|||
expected.body = "Hello there, \n\nMr. #{@recipient}"
|
||||
expected.from = "system@loudthinking.com"
|
||||
expected.date = Time.local(2004, 12, 12)
|
||||
expected.mime_version = nil
|
||||
|
||||
created = nil
|
||||
assert_nothing_raised { created = TestMailer.create_signed_up(@recipient) }
|
||||
|
@ -552,6 +570,11 @@ EOF
|
|||
assert_nothing_raised { mail.body }
|
||||
end
|
||||
|
||||
def test_multipart_with_mime_version
|
||||
mail = TestMailer.create_multipart_with_mime_version(@recipient)
|
||||
assert_equal "1.1", mail.mime_version
|
||||
end
|
||||
|
||||
def test_explicitly_multipart_messages
|
||||
mail = TestMailer.create_explicitly_multipart_example(@recipient)
|
||||
assert_equal 3, mail.parts.length
|
||||
|
@ -585,6 +608,7 @@ EOF
|
|||
def test_implicitly_multipart_messages
|
||||
mail = TestMailer.create_implicitly_multipart_example(@recipient)
|
||||
assert_equal 3, mail.parts.length
|
||||
assert_equal "1.0", mail.mime_version
|
||||
assert_equal "multipart/alternative", mail.content_type
|
||||
assert_equal "text/yaml", mail.parts[0].content_type
|
||||
assert_equal "utf-8", mail.parts[0].sub_header("content-type", "charset")
|
||||
|
|
Loading…
Reference in a new issue