Skip to content

Commit

Permalink
Merge pull request #1506 from mikel/regression/preserve-message-level…
Browse files Browse the repository at this point in the history
…-multipart-backport

Regression/preserve message level multipart backport
  • Loading branch information
mikel committed Nov 30, 2022
2 parents e7ce542 + c2a9cb6 commit 33b2a3b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/mail/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,11 @@ def add_multipart_alternate_header

def add_boundary
unless body.boundary && boundary
header['content-type'] = 'multipart/mixed' unless header['content-type']
unless header['content-type']
_charset = charset
header['content-type'] = 'multipart/mixed'
header['content-type'].parameters[:charset] = _charset
end
header['content-type'].parameters[:boundary] = ContentTypeField.generate_boundary
body.boundary = boundary
end
Expand Down
18 changes: 18 additions & 0 deletions spec/mail/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,24 @@ def self.delivering_email(mail)
end
end

describe "adding parts should preserve the charset of the mail" do
charsets = ['UTF-8', 'ISO-8859-1', nil]
charsets.each do |mail_charset|
charsets.each do |part_charset|
it "when #{mail_charset || 'nil'} vs #{part_charset || 'nil'}" do
mail = Mail.new
mail['charset'] = mail_charset
expect(mail.charset).to eq mail_charset
p = Mail::Part.new(:content_type => 'text/html', :body => 'HTML TEXT', :charset => part_charset)
expect(p.charset).to eq part_charset
mail.add_part(p)
expect(mail.charset).to eq mail_charset
expect(p.charset).to eq part_charset
end
end
end
end

describe "ordering messages" do
it "should put all attachments as the last item" do
mail = Mail.new
Expand Down

0 comments on commit 33b2a3b

Please sign in to comment.