summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2003-03-11 04:33:30 (GMT)
committerBarry Warsaw <barry@python.org>2003-03-11 04:33:30 (GMT)
commit08898499b27c899872f7ad0c6f82ac20538ba1c6 (patch)
tree11c3ce5bfdc264d2d469079cd085c59ea13b1110 /Lib/email
parent3840b49d9c2ae09ae2ccb59e2b1276c74dc3e4df (diff)
downloadcpython-08898499b27c899872f7ad0c6f82ac20538ba1c6.zip
cpython-08898499b27c899872f7ad0c6f82ac20538ba1c6.tar.gz
cpython-08898499b27c899872f7ad0c6f82ac20538ba1c6.tar.bz2
get_payload(): Teach this about various uunencoded
Content-Transfer-Encodings
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/Message.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/Lib/email/Message.py b/Lib/email/Message.py
index 4c6b3da..66f8640 100644
--- a/Lib/email/Message.py
+++ b/Lib/email/Message.py
@@ -5,6 +5,7 @@
"""
import re
+import uu
import binascii
import warnings
from cStringIO import StringIO
@@ -165,13 +166,15 @@ class Message:
the list object, you modify the message's payload in place. Optional
i returns that index into the payload.
- Optional decode is a flag (defaulting to False) indicating whether the
- payload should be decoded or not, according to the
- Content-Transfer-Encoding header. When True and the message is not a
- multipart, the payload will be decoded if this header's value is
- `quoted-printable' or `base64'. If some other encoding is used, or
- the header is missing, or if the payload has bogus base64 data, the
- payload is returned as-is (undecoded).
+ Optional decode is a flag indicating whether the payload should be
+ decoded or not, according to the Content-Transfer-Encoding header
+ (default is False).
+
+ When True and the message is not a multipart, the payload will be
+ decoded if this header's value is `quoted-printable' or `base64'. If
+ some other encoding is used, or the header is missing, or if the
+ payload has bogus data (i.e. bogus base64 or uuencoded data), the
+ payload is returned as-is.
If the message is a multipart and the decode flag is True, then None
is returned.
@@ -185,15 +188,23 @@ class Message:
if decode:
if self.is_multipart():
return None
- cte = self.get('content-transfer-encoding', '')
- if cte.lower() == 'quoted-printable':
+ cte = self.get('content-transfer-encoding', '').lower()
+ if cte == 'quoted-printable':
return Utils._qdecode(payload)
- elif cte.lower() == 'base64':
+ elif cte == 'base64':
try:
return Utils._bdecode(payload)
except binascii.Error:
# Incorrect padding
return payload
+ elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
+ sfp = StringIO()
+ try:
+ uu.decode(StringIO(payload+'\n'), sfp)
+ payload = sfp.getvalue()
+ except uu.Error:
+ # Some decoding problem
+ return payload
# Everything else, including encodings with 8bit or 7bit are returned
# unchanged.
return payload