mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Merge: #17171: fix email.encoders.encode_7or8bit when applied to binary data.
This commit is contained in:
commit
66383b2e0a
3 changed files with 24 additions and 2 deletions
|
@ -62,15 +62,17 @@ def encode_7or8bit(msg):
|
|||
else:
|
||||
orig.decode('ascii')
|
||||
except UnicodeError:
|
||||
# iso-2022-* is non-ASCII but still 7-bit
|
||||
charset = msg.get_charset()
|
||||
output_cset = charset and charset.output_charset
|
||||
# iso-2022-* is non-ASCII but encodes to a 7-bit representation
|
||||
if output_cset and output_cset.lower().startswith('iso-2022-'):
|
||||
msg['Content-Transfer-Encoding'] = '7bit'
|
||||
else:
|
||||
msg['Content-Transfer-Encoding'] = '8bit'
|
||||
else:
|
||||
msg['Content-Transfer-Encoding'] = '7bit'
|
||||
if not isinstance(orig, str):
|
||||
msg.set_payload(orig.decode('ascii', 'surrogateescape'))
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue