diff --git a/lib/mail/message.rb b/lib/mail/message.rb index 73eb1e3e4..74656df82 100644 --- a/lib/mail/message.rb +++ b/lib/mail/message.rb @@ -1771,7 +1771,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) diff --git a/spec/mail/message_spec.rb b/spec/mail/message_spec.rb index e2405cf58..6b7d834bc 100644 --- a/spec/mail/message_spec.rb +++ b/spec/mail/message_spec.rb @@ -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