[Python-checkins] python/dist/src/Lib/email Message.py,1.29,1.30
bwarsaw@users.sourceforge.net
bwarsaw@users.sourceforge.net
Mon, 10 Mar 2003 20:33:33 -0800
Update of /cvsroot/python/python/dist/src/Lib/email
In directory sc8-pr-cvs1:/tmp/cvs-serv28372
Modified Files:
Message.py
Log Message:
get_payload(): Teach this about various uunencoded
Content-Transfer-Encodings
Index: Message.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Message.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** Message.py 10 Mar 2003 16:13:14 -0000 1.29
--- Message.py 11 Mar 2003 04:33:30 -0000 1.30
***************
*** 6,9 ****
--- 6,10 ----
import re
+ import uu
import binascii
import warnings
***************
*** 166,176 ****
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).
If the message is a multipart and the decode flag is True, then None
--- 167,179 ----
i returns that index into the payload.
! 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
***************
*** 186,197 ****
if self.is_multipart():
return None
! cte = self.get('content-transfer-encoding', '')
! if cte.lower() == 'quoted-printable':
return Utils._qdecode(payload)
! elif cte.lower() == 'base64':
try:
return Utils._bdecode(payload)
except binascii.Error:
# Incorrect padding
return payload
# Everything else, including encodings with 8bit or 7bit are returned
--- 189,208 ----
if self.is_multipart():
return None
! cte = self.get('content-transfer-encoding', '').lower()
! if cte == 'quoted-printable':
return Utils._qdecode(payload)
! 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