diff options
author | José Valim and Mikel Lindsaar <pair@programming.com> | 2010-01-22 13:56:06 +0100 |
---|---|---|
committer | José Valim and Mikel Lindsaar <pair@programming.com> | 2010-01-22 13:56:06 +0100 |
commit | 1cd55928c6f638affeb5d89293f478817675d7b3 (patch) | |
tree | 9e4cf61c8dcdbf2a7aafe72cadadea53d18b79ae | |
parent | dcb925369389fa98d1548b25504c8e3a07eaeea3 (diff) | |
download | rails-1cd55928c6f638affeb5d89293f478817675d7b3.tar.gz rails-1cd55928c6f638affeb5d89293f478817675d7b3.tar.bz2 rails-1cd55928c6f638affeb5d89293f478817675d7b3.zip |
First work on implicit multipart.
4 files changed, 44 insertions, 25 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 1f432c2a80..fb1dab7c39 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -401,21 +401,18 @@ module ActionMailer #:nodoc: :default => action_name.humanize) # Give preference to headers and fallbacks to the ones set in mail - headers[:content_type] ||= m.content_type - headers[:charset] ||= m.charset - headers[:mime_version] ||= m.mime_version - - m.content_type = headers[:content_type] || self.class.default_content_type.dup - m.charset = headers[:charset] || self.class.default_charset.dup - m.mime_version = headers[:mime_version] || self.class.default_mime_version.dup - - m.subject ||= quote_if_necessary(headers[:subject], m.charset) if headers[:subject] - m.to ||= quote_address_if_necessary(headers[:to], m.charset) if headers[:to] - m.from ||= quote_address_if_necessary(headers[:from], m.charset) if headers[:from] - m.cc ||= quote_address_if_necessary(headers[:cc], m.charset) if headers[:cc] - m.bcc ||= quote_address_if_necessary(headers[:bcc], m.charset) if headers[:bcc] - m.reply_to ||= quote_address_if_necessary(headers[:reply_to], m.charset) if headers[:reply_to] - m.date ||= headers[:date] if headers[:date] + content_type = headers[:content_type] || m.content_type + charset = headers[:charset] || m.charset + mime_version = headers[:mime_version] || m.mime_version + body = nil + + m.subject ||= quote_if_necessary(headers[:subject], charset) if headers[:subject] + m.to ||= quote_address_if_necessary(headers[:to], charset) if headers[:to] + m.from ||= quote_address_if_necessary(headers[:from], charset) if headers[:from] + m.cc ||= quote_address_if_necessary(headers[:cc], charset) if headers[:cc] + m.bcc ||= quote_address_if_necessary(headers[:bcc], charset) if headers[:bcc] + m.reply_to ||= quote_address_if_necessary(headers[:reply_to], charset) if headers[:reply_to] + m.date ||= headers[:date] if headers[:date] if block_given? # Do something @@ -424,25 +421,29 @@ module ActionMailer #:nodoc: templates = self.class.template_root.find_all(action_name, {}, mailer_name) if templates.size == 1 - unless headers[:content_type] - proper_charset = m.charset - m.content_type = templates[0].mime_type.to_s - m.charset = proper_charset - end + content_type ||= templates[0].mime_type.to_s m.body = render_to_body(:_template => templates[0]) else + content_type ||= "multipart/alternate" + templates.each do |template| part = Mail::Part.new part.content_type = template.mime_type.to_s - part.charset = m.charset + part.charset = charset part.body = render_to_body(:_template => template) + m.add_part(part) end end end + + m.content_type = content_type || self.class.default_content_type.dup + m.charset = charset || self.class.default_charset.dup + m.mime_version = mime_version || self.class.default_mime_version.dup + + # TODO Add me and test me + # m.body.set_sort_order(headers[:parts_order] || self.class.default_implicit_parts_order.dup) + # m.body.sort_parts! - m.body.set_sort_order(headers[:parts_order] || self.class.default_implicit_parts_order.dup) - - # TODO: m.body.sort_parts! m end diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index f22b20a6ba..8502b29ba4 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -62,6 +62,10 @@ class BaseTest < ActiveSupport::TestCase :transfer_encoding => "base64" } mail(DEFAULT_HEADERS) end + + def implicit_multipart + mail(DEFAULT_HEADERS) + end end test "method call to mail does not raise error" do @@ -156,7 +160,19 @@ class BaseTest < ActiveSupport::TestCase email = BaseMailer.deliver_welcome(:subject => nil) assert_equal "New Subject!", email.subject end - + + test "implicit multipart tests" do + require 'ruby-debug' + $BREAK = true + email = BaseMailer.deliver_implicit_multipart + + assert_equal(2, email.parts.size) + + assert_equal("multipart/alternate", email.mime_type) + assert_equal("text/plain", email.parts[0].mime_type) + assert_equal("text/html", email.parts[1].mime_type) + end + protected # Execute the block setting the given values and restoring old values after diff --git a/actionmailer/test/fixtures/base_mailer/implicit_multipart.html.erb b/actionmailer/test/fixtures/base_mailer/implicit_multipart.html.erb new file mode 100644 index 0000000000..23745cd282 --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/implicit_multipart.html.erb @@ -0,0 +1 @@ +HTML Implicit Multipart
\ No newline at end of file diff --git a/actionmailer/test/fixtures/base_mailer/implicit_multipart.text.erb b/actionmailer/test/fixtures/base_mailer/implicit_multipart.text.erb new file mode 100644 index 0000000000..d51437fc72 --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/implicit_multipart.text.erb @@ -0,0 +1 @@ +TEXT Implicit Multipart
\ No newline at end of file |