diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-02-11 15:54:22 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-02-11 15:54:22 (GMT) |
commit | 64634eb32112c84b858ba58729e7c7246affad34 (patch) | |
tree | da274d94f4994824cc5be10affcc4a65f6152546 /Lib/email | |
parent | a6e902ae35179349b24702f9eb3eb37fb31481b8 (diff) | |
parent | 66383b2e0a47cebf31586a1038e85d37c9aefadc (diff) | |
download | cpython-64634eb32112c84b858ba58729e7c7246affad34.zip cpython-64634eb32112c84b858ba58729e7c7246affad34.tar.gz cpython-64634eb32112c84b858ba58729e7c7246affad34.tar.bz2 |
Merge: #17171: fix email.encoders.encode_7or8bit when applied to binary data.
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/encoders.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/email/encoders.py b/Lib/email/encoders.py index 88b2f57..82a28cf 100644 --- a/Lib/email/encoders.py +++ b/Lib/email/encoders.py @@ -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')) |