summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-06-27 22:38:36 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-06-27 22:38:36 (GMT)
commitc723da361a8d5129ec9bd336e6327a65b4e92148 (patch)
tree2dca9621ff0ad08f1463735ff97e7e369ad2125c /Lib/email
parentcd83fa8c3e8509418215c55b89e52160dc38e50d (diff)
parentf6069f9f22a81a0b9f81a1cc43fb0896e70f5379 (diff)
downloadcpython-c723da361a8d5129ec9bd336e6327a65b4e92148.zip
cpython-c723da361a8d5129ec9bd336e6327a65b4e92148.tar.gz
cpython-c723da361a8d5129ec9bd336e6327a65b4e92148.tar.bz2
Merge #14360: make encoders.encode_quopri work.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/encoders.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/email/encoders.py b/Lib/email/encoders.py
index 82a28cf..a0d062a 100644
--- a/Lib/email/encoders.py
+++ b/Lib/email/encoders.py
@@ -20,7 +20,7 @@ from quopri import encodestring as _encodestring
def _qencode(s):
enc = _encodestring(s, quotetabs=True)
# Must encode spaces, which quopri.encodestring() doesn't do
- return enc.replace(' ', '=20')
+ return enc.replace(b' ', b'=20')
def encode_base64(msg):
@@ -41,8 +41,12 @@ def encode_quopri(msg):
Also, add an appropriate Content-Transfer-Encoding header.
"""
orig = msg.get_payload()
+ if isinstance(orig, str):
+ # If it is a string, the model data may have binary data encoded in via
+ # surrogateescape. Convert back to bytes so we can CTE encode it.
+ orig = orig.encode('ascii', 'surrogateescape')
encdata = _qencode(orig)
- msg.set_payload(encdata)
+ msg.set_payload(encdata.decode('ascii', 'surrogateescape'))
msg['Content-Transfer-Encoding'] = 'quoted-printable'