summaryrefslogtreecommitdiffstats
path: root/Lib/email/message.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-05-28 01:23:34 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-05-28 01:23:34 (GMT)
commit80e0aee95b8c4a7da8a1b794793a9e9537d021cf (patch)
tree36bc2ab00ee8552d10ea4b92f80f9bf9355a55fd /Lib/email/message.py
parentadbdcdbd9527a3c4000cd4ff0678ff60151f1f79 (diff)
downloadcpython-80e0aee95b8c4a7da8a1b794793a9e9537d021cf.zip
cpython-80e0aee95b8c4a7da8a1b794793a9e9537d021cf.tar.gz
cpython-80e0aee95b8c4a7da8a1b794793a9e9537d021cf.tar.bz2
#1672568: email now registers defects for base64 payload format errors.
Which also means that it is now producing *something* for any base64 payload, which is what leads to the couple of older test changes in test_email. This is a slightly backward incompatible behavior change, but the new behavior is so much more useful than the old (you can now *reliably* detect errors, and any program that was detecting errors by sniffing for a base64 return from get_payload(decode=True) and then doing its own error-recovery decode will just get the error-recovery decode right away). So this seems to me to be worth the small risk inherent in this behavior change. This patch also refactors the defect tests into a separate test file, since they are no longer just parser tests.
Diffstat (limited to 'Lib/email/message.py')
-rw-r--r--Lib/email/message.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/email/message.py b/Lib/email/message.py
index 91976f1..62b82b7 100644
--- a/Lib/email/message.py
+++ b/Lib/email/message.py
@@ -17,6 +17,7 @@ from email import utils
from email import errors
from email._policybase import compat32
from email import charset as _charset
+from email._encoded_words import decode_b
Charset = _charset.Charset
SEMISPACE = '; '
@@ -249,11 +250,12 @@ class Message:
if cte == 'quoted-printable':
return utils._qdecode(bpayload)
elif cte == 'base64':
- try:
- return base64.b64decode(bpayload)
- except binascii.Error:
- # Incorrect padding
- return bpayload
+ # XXX: this is a bit of a hack; decode_b should probably be factored
+ # out somewhere, but I haven't figured out where yet.
+ value, defects = decode_b(b''.join(bpayload.splitlines()))
+ for defect in defects:
+ self.policy.handle_defect(self, defect)
+ return value
elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
in_file = BytesIO(bpayload)
out_file = BytesIO()