Skip to content

Commit

Permalink
Allow specific "multipart/xxx" content-type to be set on multipart me…
Browse files Browse the repository at this point in the history
…ssages #1412 [Flurin Egger]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1493 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jamis committed Jun 24, 2005
1 parent 0d8455c commit 3b4eb7a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions actionmailer/CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN* *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 * Unquoted @ characters in headers are now accepted in spite of RFC 822 #1206


* Helper support (borrowed from ActionPack) * Helper support (borrowed from ActionPack)
Expand Down
2 changes: 2 additions & 0 deletions actionmailer/lib/action_mailer/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ def create_mail
part = (TMail::Mail === p ? p : p.to_mail(self)) part = (TMail::Mail === p ? p : p.to_mail(self))
m.parts << part m.parts << part
end end

m.set_content_type(content_type, nil, { "charset" => charset }) if content_type =~ /multipart/
end end


@mail = m @mail = m
Expand Down
27 changes: 21 additions & 6 deletions actionmailer/test/mail_service_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ def utf8_body(recipient)
@charset = "utf-8" @charset = "utf-8"
end end


def explicitly_multipart_example(recipient) def explicitly_multipart_example(recipient, ct=nil)
@recipients = recipient recipients recipient
@subject = "multipart example" subject "multipart example"
@from = "test@example.com" from "test@example.com"
@sent_on = Time.local 2004, 12, 12 sent_on Time.local(2004, 12, 12)
@body = "plain text default" body "plain text default"
content_type ct if ct


part "text/html" do |p| part "text/html" do |p|
p.charset = "iso-8859-1" p.charset = "iso-8859-1"
Expand Down Expand Up @@ -462,6 +463,7 @@ def test_decode_message_with_incorrect_charset
def test_explicitly_multipart_messages def test_explicitly_multipart_messages
mail = TestMailer.create_explicitly_multipart_example(@recipient) mail = TestMailer.create_explicitly_multipart_example(@recipient)
assert_equal 3, mail.parts.length assert_equal 3, mail.parts.length
assert_nil mail.content_type
assert_equal "text/plain", mail.parts[0].content_type assert_equal "text/plain", mail.parts[0].content_type


assert_equal "text/html", mail.parts[1].content_type assert_equal "text/html", mail.parts[1].content_type
Expand All @@ -475,6 +477,19 @@ def test_explicitly_multipart_messages
assert_nil mail.parts[2].sub_header("content-type", "charset") assert_nil mail.parts[2].sub_header("content-type", "charset")
end 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 def test_implicitly_multipart_messages
mail = TestMailer.create_implicitly_multipart_example(@recipient) mail = TestMailer.create_implicitly_multipart_example(@recipient)
assert_equal 2, mail.parts.length assert_equal 2, mail.parts.length
Expand Down

0 comments on commit 3b4eb7a

Please sign in to comment.