From f1046ca8173380e2c320c56e1cdc911493371057 Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Tue, 27 Jul 2010 21:20:15 +0000 Subject: Issue #4770: Restrict binascii module to accept only bytes (as specified). And fix the email package to encode to ASCII instead of ``raw-unicode-escape`` before ASCII-to-binary decoding. --- Lib/email/base64mime.py | 4 ++-- Lib/email/message.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'Lib/email') diff --git a/Lib/email/base64mime.py b/Lib/email/base64mime.py index 6cbfdf6ad8..f3bbac1caf 100644 --- a/Lib/email/base64mime.py +++ b/Lib/email/base64mime.py @@ -74,12 +74,12 @@ def header_encode(header_bytes, charset='iso-8859-1'): def body_encode(s, maxlinelen=76, eol=NL): - """Encode a string with base64. + r"""Encode a string with base64. Each line will be wrapped at, at most, maxlinelen characters (defaults to 76 characters). - Each line of encoded text will end with eol, which defaults to "\\n". Set + Each line of encoded text will end with eol, which defaults to "\n". Set this to "\r\n" if you will be using the result of this function directly in an email. """ diff --git a/Lib/email/message.py b/Lib/email/message.py index 27a577dac7..520d63d713 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -198,17 +198,19 @@ class Message: return None cte = self.get('content-transfer-encoding', '').lower() if cte == 'quoted-printable': + if isinstance(payload, str): + payload = payload.encode('ascii') return utils._qdecode(payload) elif cte == 'base64': try: if isinstance(payload, str): - payload = payload.encode('raw-unicode-escape') + payload = payload.encode('ascii') return base64.b64decode(payload) except binascii.Error: # Incorrect padding pass elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'): - in_file = BytesIO(payload.encode('raw-unicode-escape')) + in_file = BytesIO(payload.encode('ascii')) out_file = BytesIO() try: uu.decode(in_file, out_file, quiet=True) -- cgit v1.2.1