aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/base.rb
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-08-22 23:53:04 +0000
committerJamis Buck <jamis@37signals.com>2005-08-22 23:53:04 +0000
commitdca4d4e86d7fa753428d24a8ab33dc08a0401581 (patch)
tree9af4835126dacf6b8d8fe086207392b5e00f2f7b /actionmailer/lib/action_mailer/base.rb
parentae1e85200e1480a47db7c3ccfcc7d256f37e88ba (diff)
downloadrails-dca4d4e86d7fa753428d24a8ab33dc08a0401581.tar.gz
rails-dca4d4e86d7fa753428d24a8ab33dc08a0401581.tar.bz2
rails-dca4d4e86d7fa753428d24a8ab33dc08a0401581.zip
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
Diffstat (limited to 'actionmailer/lib/action_mailer/base.rb')
-rw-r--r--actionmailer/lib/action_mailer/base.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 96574fcfd9..089b2ef0f6 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -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
@@ -150,13 +153,16 @@ 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 }