summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-02-11 15:53:35 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-02-11 15:53:35 (GMT)
commit66383b2e0a47cebf31586a1038e85d37c9aefadc (patch)
tree84298353566c67b893ef249923d42a297418332a /Lib/email
parent0b61d3c0f2a818355e6bfcbf79c4f47875c10b15 (diff)
parentec317a8985967a7c8f150ec8c5db42443a18bdbe (diff)
downloadcpython-66383b2e0a47cebf31586a1038e85d37c9aefadc.zip
cpython-66383b2e0a47cebf31586a1038e85d37c9aefadc.tar.gz
cpython-66383b2e0a47cebf31586a1038e85d37c9aefadc.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.py4
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'))