gh-150771: Fix email serialization for shift_jis and euc-jp#151120
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
5928e5b to
f071b32
Compare
Convert surrogate-escaped payloads through the input charset before encoding to iso-2022-jp, fixing UnicodeEncodeError when printing messages created with set_content().
f071b32 to
6795f58
Compare
…/euc-jp Encode the payload with the charset output mapping (iso-2022-jp) when set_content is called with shift_jis or euc-jp, instead of patching serialization in body_encode and set_payload. Reverts those changes.
Use plain backticks for set_content() instead of a broken :func: target.
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM. 👍
Do you think an assertion for bytes(m) would be useful?
Mirror test_set_text_charset_cp949 per review feedback. Co-authored-by: Cursor <cursoragent@cursor.com>
Match cp949 test style per review feedback.
|
Thanks @bhuvi27 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Thanks @bhuvi27 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
Thanks @bhuvi27 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Sorry, @bhuvi27 and @serhiy-storchaka, I could not cleanly backport this to |
|
Sorry, @bhuvi27 and @serhiy-storchaka, I could not cleanly backport this to |
|
GH-151541 is a backport of this pull request to the 3.15 branch. |
…thonGH-151120) Encode the payload with output_charset instead of input_charset.
Fixes #150771
Creating a message with set_content(..., charset='shift_jis') or charset='euc-jp' raised UnicodeEncodeError on str(m) because the payload was encoded with the input charset while the Content-Type uses the output
charset (iso-2022-jp).
Use Charset.output_charset in set_text_content so the payload and Content-Type agree from the start.