Skip to content

Commit

Permalink
fix issue 208 "mail.body after mail.add_file truncates message body"
Browse files Browse the repository at this point in the history
  • Loading branch information
glongman committed Mar 21, 2011
1 parent 6a0bd67 commit fe9d9dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mail/part.rb
Expand Up @@ -103,7 +103,7 @@ def parse_message
self.body = body_part
else
self.header = "Content-Type: text/plain\r\n"
self.body = header_part
self.body = raw_source
end
end

Expand Down
15 changes: 15 additions & 0 deletions spec/mail/mime_messages_spec.rb
Expand Up @@ -455,6 +455,21 @@
m.parts.first[:content_type].content_type.should == 'image/png'
m.parts.last[:content_type].content_type.should == 'text/plain'
end

it "should allow you to add a body as text part if you have added a file and not truncate after newlines - issue 208" do
m = Mail.new do
from 'mikel@from.lindsaar.net'
subject 'Hello there Mikel'
to 'mikel@to.lindsaar.net'
add_file fixture('attachments', 'test.png')
body "First Line\n\nSecond Line\n\nThird Line\n\n"
#Note: trailing \n\n is stripped off by Mail::Part initialization
end
m.parts.length.should == 2
m.parts.first[:content_type].content_type.should == 'image/png'
m.parts.last[:content_type].content_type.should == 'text/plain'
m.parts.last.to_s.should match /^First Line\r\n\r\nSecond Line\r\n\r\nThird Line/
end

end

Expand Down
8 changes: 8 additions & 0 deletions spec/mail/part_spec.rb
Expand Up @@ -141,5 +141,13 @@
end

end

it "should correctly parse plain text raw source and not truncate after newlines - issue 208" do
plain_text = "First Line\n\nSecond Line\n\nThird Line\n\n"
#Note: trailing \n\n is stripped off by Mail::Part initialization
part = Mail::Part.new(plain_text)
part[:content_type].content_type.should == 'text/plain'
part.to_s.should match /^First Line\r\n\r\nSecond Line\r\n\r\nThird Line/
end

end

0 comments on commit fe9d9dd

Please sign in to comment.