Skip to content

Commit 1d32cec

Browse files
committed
Allow body to be specified for nested parts with action mailer. Closes rails#10271 [redinger]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8238 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
1 parent fd3f048 commit 1d32cec

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

actionmailer/lib/action_mailer/part.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,8 @@ def to_mail(defaults)
8484
end
8585
else
8686
if String === body
87-
part = TMail::Mail.new
88-
part.body = body
89-
part.set_content_type(real_content_type, nil, ctype_attrs)
90-
part.set_content_disposition "inline"
91-
m.parts << part
87+
@parts.unshift Part.new(:charset => charset, :body => @body, :content_type => 'text/plain')
88+
@body = nil
9289
end
9390

9491
@parts.each do |p|

actionmailer/test/mail_service_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ def nested_multipart(recipient)
210210
attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
211211
end
212212

213+
def nested_multipart_with_body(recipient)
214+
recipients recipient
215+
subject "nested multipart with body"
216+
217+
content_type "multipart/mixed"
218+
part :content_type => "multipart/alternative", :content_disposition => "inline", :body => "Nothing to see here." do |p|
219+
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>"
220+
end
221+
end
222+
213223
def attachment_with_custom_header(recipient)
214224
recipients recipient
215225
subject "custom header in attachment"
@@ -310,6 +320,19 @@ def test_nested_parts
310320
assert_equal "application/octet-stream", created.parts[1].content_type
311321
end
312322

323+
def test_nested_parts_with_body
324+
created = nil
325+
assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)}
326+
assert_equal 1,created.parts.size
327+
assert_equal 2,created.parts.first.parts.size
328+
329+
assert_equal "multipart/mixed", created.content_type
330+
assert_equal "multipart/alternative", created.parts.first.content_type
331+
assert_equal "Nothing to see here.", created.parts.first.parts.first.body
332+
assert_equal "text/plain", created.parts.first.parts.first.content_type
333+
assert_equal "text/html", created.parts.first.parts[1].content_type
334+
end
335+
313336
def test_attachment_with_custom_header
314337
created = nil
315338
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient)}

0 commit comments

Comments
 (0)