[Python-checkins] CVS: python/dist/src/Lib/email Parser.py,1.1,1.2
Barry Warsaw
bwarsaw@users.sourceforge.net
Tue, 25 Sep 2001 22:44:11 -0700
Update of /cvsroot/python/python/dist/src/Lib/email
In directory usw-pr-cvs1:/tmp/cvs-serv28784
Modified Files:
Parser.py
Log Message:
_parsebody(): Use get_boundary() and get_type().
Also, add a clause to the big-if to handle message/delivery-status
content types. These create a message with subparts that are
Message instances, which best represent the header blocks of this
content type.
Index: Parser.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Parser.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Parser.py 2001/09/23 03:17:28 1.1
--- Parser.py 2001/09/26 05:44:09 1.2
***************
*** 5,9 ****
"""
- import re
from cStringIO import StringIO
--- 5,8 ----
***************
*** 12,16 ****
import Message
- bcre = re.compile('boundary="?([^"]+)"?', re.IGNORECASE)
EMPTYSTRING = ''
NL = '\n'
--- 11,14 ----
***************
*** 93,103 ****
# Parse the body, but first split the payload on the content-type
# boundary if present.
! boundary = isdigest = None
! ctype = container['content-type']
! if ctype:
! mo = bcre.search(ctype)
! if mo:
! boundary = mo.group(1)
! isdigest = container.get_type() == 'multipart/digest'
# If there's a boundary, split the payload text into its constituent
# parts and parse each separately. Otherwise, just parse the rest of
--- 91,96 ----
# Parse the body, but first split the payload on the content-type
# boundary if present.
! boundary = container.get_boundary()
! isdigest = (container.get_type() == 'multipart/digest')
# If there's a boundary, split the payload text into its constituent
# parts and parse each separately. Otherwise, just parse the rest of
***************
*** 142,146 ****
container.epilogue = epilogue
container.add_payload(msgobj)
! elif ctype == 'message/rfc822':
# Create a container for the payload, but watch out for there not
# being any headers left
--- 135,152 ----
container.epilogue = epilogue
container.add_payload(msgobj)
! elif container.get_type() == 'message/delivery-status':
! # This special kind of type contains blocks of headers separated
! # by a blank line. We'll represent each header block as a
! # separate Message object
! blocks = []
! while 1:
! blockmsg = self._class()
! self._parseheaders(blockmsg, fp)
! if not len(blockmsg):
! # No more header blocks left
! break
! blocks.append(blockmsg)
! container.set_payload(blocks)
! elif container.get_main_type() == 'message':
# Create a container for the payload, but watch out for there not
# being any headers left