mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-27321 Fix email.generator.py to not replace a non-existent header. (GH-18074)
This PR replaces GH-1977. The reason for the replacement is two-fold.
The fix itself is different is that if the CTE header doesn't exist in the original message, it is inserted. This is important because the new CTE could be quoted-printable whereas the original is implicit 8bit.
Also the tests are different. The test_nonascii_as_string_without_cte test in GH-1977 doesn't actually test the issue in that it passes without the fix. The test_nonascii_as_string_without_content_type_and_cte test is improved here, and even though it doesn't fail without the fix, it is included for completeness.
Automerge-Triggered-By: @warsaw
(cherry picked from commit bf838227c3
)
Co-authored-by: Mark Sapiro <mark@msapiro.net>
This commit is contained in:
parent
335eb57823
commit
72ce82abcf
3 changed files with 42 additions and 1 deletions
|
@ -186,7 +186,11 @@ class Generator:
|
|||
# If we munged the cte, copy the message again and re-fix the CTE.
|
||||
if munge_cte:
|
||||
msg = deepcopy(msg)
|
||||
msg.replace_header('content-transfer-encoding', munge_cte[0])
|
||||
# Preserve the header order if the CTE header already exists.
|
||||
if msg.get('content-transfer-encoding') is None:
|
||||
msg['Content-Transfer-Encoding'] = munge_cte[0]
|
||||
else:
|
||||
msg.replace_header('content-transfer-encoding', munge_cte[0])
|
||||
msg.replace_header('content-type', munge_cte[1])
|
||||
# Write the headers. First we see if the message object wants to
|
||||
# handle that itself. If not, we'll do it generically.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue