Skip to content

Commit

Permalink
Allow body to be specified for nested parts with action mailer. Closes
Browse files Browse the repository at this point in the history
rails#10271 [redinger]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8238 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Nov 29, 2007
1 parent fd3f048 commit 1d32cec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
7 changes: 2 additions & 5 deletions actionmailer/lib/action_mailer/part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ def to_mail(defaults)
end
else
if String === body
part = TMail::Mail.new
part.body = body
part.set_content_type(real_content_type, nil, ctype_attrs)
part.set_content_disposition "inline"
m.parts << part
@parts.unshift Part.new(:charset => charset, :body => @body, :content_type => 'text/plain')
@body = nil
end

@parts.each do |p|
Expand Down
23 changes: 23 additions & 0 deletions actionmailer/test/mail_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,16 @@ def nested_multipart(recipient)
attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
end

def nested_multipart_with_body(recipient)
recipients recipient
subject "nested multipart with body"
from "test@example.com"
content_type "multipart/mixed"
part :content_type => "multipart/alternative", :content_disposition => "inline", :body => "Nothing to see here." do |p|
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>"
end
end

def attachment_with_custom_header(recipient)
recipients recipient
subject "custom header in attachment"
Expand Down Expand Up @@ -310,6 +320,19 @@ def test_nested_parts
assert_equal "application/octet-stream", created.parts[1].content_type
end

def test_nested_parts_with_body
created = nil
assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)}
assert_equal 1,created.parts.size
assert_equal 2,created.parts.first.parts.size

assert_equal "multipart/mixed", created.content_type
assert_equal "multipart/alternative", created.parts.first.content_type
assert_equal "Nothing to see here.", created.parts.first.parts.first.body
assert_equal "text/plain", created.parts.first.parts.first.content_type
assert_equal "text/html", created.parts.first.parts[1].content_type
end

def test_attachment_with_custom_header
created = nil
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient)}
Expand Down

0 comments on commit 1d32cec

Please sign in to comment.