mail icon indicating copy to clipboard operation
mail copied to clipboard

2.8.0.rc1 Regression: Preserve message-level charset when adding parts (related to Rails ActionMailer)

Open johnnyshields opened this issue 3 years ago • 1 comments
trafficstars

Please also backport to 2.8.x stable branch

Summary

Version 2.8.0.rc1 has a regression where charset=UTF-8 is omitted from the Content-Type header in multi-part (text + html) mails. Due to this regression, some of our Japanese customers reported their legacy mail clients had garbled characters. It appears the legacy mail clients assume some other encoding besides UTF-8 if it's not present (probably Shift-JIS in our case).

The fix I've proposed here doesn't appear to alter any existing behavior.

Details

In ActionMailer::Base, there is this code:

          container = Mail::Part.new
          container.content_type = "multipart/alternative"
          responses.each { |r| insert_part(container, r, m.charset) }
          m.add_part(container)

On Mail 2.8.0.rc1, adding both an HTML and Text part (i.e. in the standard Rails way, no special code) will inadvertently clear the charset on the parent Message. In the final rendered mail, it causes charset=UTF-8 to be omitted the Content-Type header. Compare as follows:

2.7.x:

----==_mimepart_62c78ac27c197_36459c77334
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64

DQrkuojntITnorrlrpoNCg0K44GK5a6i5qeY44Gu44GU5LqI57SE44GM56K65a6a6Ie044GX44G+...

2.8.0.rc1:

----==_mimepart_62c78ac27de6f_a2459c7627b
Content-Type: text/plain
Content-Transfer-Encoding: base64

DQrkuojntITnorrlrpoNCg0K44GK5a6i5qeY44Gu44GU5LqI57SE44GM56K65a6a6Ie044GX44G+...

johnnyshields avatar Jul 09 '22 14:07 johnnyshields

@mikel please take a look when you get a chance.

johnnyshields avatar Jul 24 '22 12:07 johnnyshields

Merged to 2.8.0.rc1 as well in https://github.com/mikel/mail/pull/1506

mikel avatar Nov 30 '22 07:11 mikel

@mikel awesome I really appreciate it 🎉

johnnyshields avatar Nov 30 '22 07:11 johnnyshields