Skip to content

Commit d1d65b3

Browse files
authored
Merge pull request #1330 from jeremyevans/content-type-regression-fix
Fix regression in content_type for text part after converted to multipart
2 parents 30302c7 + 89f55e5 commit d1d65b3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/mail/message.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ def add_file(values)
17781778
private_constant :MULTIPART_CONVERSION_CONTENT_FIELDS if respond_to?(:private_constant)
17791779

17801780
def convert_to_multipart
1781-
text_part = Mail::Part.new(:body => body.decoded)
1781+
text_part = Mail::Part.new(:content_type => 'text/plain;', :body => body.decoded)
17821782

17831783
MULTIPART_CONVERSION_CONTENT_FIELDS.each do |field_name|
17841784
if value = send(field_name)

spec/mail/message_spec.rb

+22
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,28 @@ def message_headers_should_match(message, other)
15071507
end
15081508
end
15091509

1510+
describe "add_file sets content_type from attachment" do
1511+
it "should work if set before body" do
1512+
m = Mail.new
1513+
m.add_file :filename=>'a.txt', :content=>'b'
1514+
m.body 'c'
1515+
expect(m.parts.first.content_type).to match(/text\/plain/)
1516+
expect(m.parts.first.body.encoded).to eq('b')
1517+
expect(m.parts.last.content_type).to match(/text\/plain/)
1518+
expect(m.parts.last.body.encoded).to eq('c')
1519+
end
1520+
1521+
it "should work if set after body" do
1522+
m = Mail.new
1523+
m.body 'c'
1524+
m.add_file :filename=>'a.txt', :content=>'b'
1525+
expect(m.parts.first.content_type).to match(/text\/plain/)
1526+
expect(m.parts.first.body.encoded).to eq('c')
1527+
expect(m.parts.last.content_type).to match(/text\/plain/)
1528+
expect(m.parts.last.body.encoded).to eq('b')
1529+
end
1530+
end
1531+
15101532
describe "content-transfer-encoding" do
15111533

15121534
it "should use 7bit for only US-ASCII chars" do

0 commit comments

Comments
 (0)