summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
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'))