From dca4d4e86d7fa753428d24a8ab33dc08a0401581 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Mon, 22 Aug 2005 23:53:04 +0000 Subject: 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 --- actionmailer/lib/action_mailer/base.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'actionmailer/lib/action_mailer/base.rb') 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 @charset. # * default_content_type - 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 @content_type. + # * default_mime_version - The default mime version used for the message. Defaults to nil. You + # can also pick a different value from inside a method with @mime_version. When multipart messages are in + # use, @mime_version will be set to "1.0" if it is not set inside a method. # * default_implicit_parts_order - 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 } -- cgit v1.2.3