aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-06-24 12:15:45 +0000
committerJamis Buck <jamis@37signals.com>2005-06-24 12:15:45 +0000
commit3b4eb7aece771cb0cce131e55dbdc8137a118512 (patch)
tree17a9eea794e228d82d53902d5c8d8cdaaf67223f
parent0d8455c1a285c6d58fc7a3180f5c72d9c3c42fa1 (diff)
downloadrails-3b4eb7aece771cb0cce131e55dbdc8137a118512.tar.gz
rails-3b4eb7aece771cb0cce131e55dbdc8137a118512.tar.bz2
rails-3b4eb7aece771cb0cce131e55dbdc8137a118512.zip
Allow specific "multipart/xxx" content-type to be set on multipart messages #1412 [Flurin Egger]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1493 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionmailer/CHANGELOG2
-rw-r--r--actionmailer/lib/action_mailer/base.rb2
-rwxr-xr-xactionmailer/test/mail_service_test.rb27
3 files changed, 25 insertions, 6 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG
index 2ac696fba7..353472c775 100644
--- a/actionmailer/CHANGELOG
+++ b/actionmailer/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Allow specific "multipart/xxx" content-type to be set on multipart messages #1412 [Flurin Egger]
+
* Unquoted @ characters in headers are now accepted in spite of RFC 822 #1206
* Helper support (borrowed from ActionPack)
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 7154dbdc93..a8880146af 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -278,6 +278,8 @@ module ActionMailer #:nodoc:
part = (TMail::Mail === p ? p : p.to_mail(self))
m.parts << part
end
+
+ m.set_content_type(content_type, nil, { "charset" => charset }) if content_type =~ /multipart/
end
@mail = m
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index 8eb001ab25..7efd044796 100755
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -94,12 +94,13 @@ class TestMailer < ActionMailer::Base
@charset = "utf-8"
end
- def explicitly_multipart_example(recipient)
- @recipients = recipient
- @subject = "multipart example"
- @from = "test@example.com"
- @sent_on = Time.local 2004, 12, 12
- @body = "plain text default"
+ def explicitly_multipart_example(recipient, ct=nil)
+ recipients recipient
+ subject "multipart example"
+ from "test@example.com"
+ sent_on Time.local(2004, 12, 12)
+ body "plain text default"
+ content_type ct if ct
part "text/html" do |p|
p.charset = "iso-8859-1"
@@ -462,6 +463,7 @@ EOF
def test_explicitly_multipart_messages
mail = TestMailer.create_explicitly_multipart_example(@recipient)
assert_equal 3, mail.parts.length
+ assert_nil mail.content_type
assert_equal "text/plain", mail.parts[0].content_type
assert_equal "text/html", mail.parts[1].content_type
@@ -475,6 +477,19 @@ EOF
assert_nil mail.parts[2].sub_header("content-type", "charset")
end
+ def test_explicitly_multipart_with_content_type
+ mail = TestMailer.create_explicitly_multipart_example(@recipient,
+ "multipart/alternative")
+ assert_equal 3, mail.parts.length
+ assert_equal "multipart/alternative", mail.content_type
+ end
+
+ def test_explicitly_multipart_with_invalid_content_type
+ mail = TestMailer.create_explicitly_multipart_example(@recipient, "text/xml")
+ assert_equal 3, mail.parts.length
+ assert_nil mail.content_type
+ end
+
def test_implicitly_multipart_messages
mail = TestMailer.create_implicitly_multipart_example(@recipient)
assert_equal 2, mail.parts.length