Skip to content

Commit

Permalink
Merge pull request #1330 from jeremyevans/content-type-regression-fix
Browse files Browse the repository at this point in the history
Fix regression in content_type for text part after converted to multipart
  • Loading branch information
radar authored Jan 21, 2025
2 parents 30302c7 + 89f55e5 commit d1d65b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mail/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ def add_file(values)
private_constant :MULTIPART_CONVERSION_CONTENT_FIELDS if respond_to?(:private_constant)

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

MULTIPART_CONVERSION_CONTENT_FIELDS.each do |field_name|
if value = send(field_name)
Expand Down
22 changes: 22 additions & 0 deletions spec/mail/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,28 @@ def message_headers_should_match(message, other)
end
end

describe "add_file sets content_type from attachment" do
it "should work if set before body" do
m = Mail.new
m.add_file :filename=>'a.txt', :content=>'b'
m.body 'c'
expect(m.parts.first.content_type).to match(/text\/plain/)
expect(m.parts.first.body.encoded).to eq('b')
expect(m.parts.last.content_type).to match(/text\/plain/)
expect(m.parts.last.body.encoded).to eq('c')
end

it "should work if set after body" do
m = Mail.new
m.body 'c'
m.add_file :filename=>'a.txt', :content=>'b'
expect(m.parts.first.content_type).to match(/text\/plain/)
expect(m.parts.first.body.encoded).to eq('c')
expect(m.parts.last.content_type).to match(/text\/plain/)
expect(m.parts.last.body.encoded).to eq('b')
end
end

describe "content-transfer-encoding" do

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

0 comments on commit d1d65b3

Please sign in to comment.