diff options
author | Barry Warsaw <barry@python.org> | 2001-09-26 05:44:09 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2001-09-26 05:44:09 (GMT) |
commit | 66971fbca586a87ba247eaf806938384b0e41492 (patch) | |
tree | 0221b737318e602079acd79500bb0f385fb1efd9 /Lib/email | |
parent | beb5945c65f13e181409c09d89795673c4f73162 (diff) | |
download | cpython-66971fbca586a87ba247eaf806938384b0e41492.zip cpython-66971fbca586a87ba247eaf806938384b0e41492.tar.gz cpython-66971fbca586a87ba247eaf806938384b0e41492.tar.bz2 |
_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.
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/Parser.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/Lib/email/Parser.py b/Lib/email/Parser.py index cc23d19..81763dc 100644 --- a/Lib/email/Parser.py +++ b/Lib/email/Parser.py @@ -4,14 +4,12 @@ """A parser of RFC 2822 and MIME email messages. """ -import re from cStringIO import StringIO # Intrapackage imports import Errors import Message -bcre = re.compile('boundary="?([^"]+)"?', re.IGNORECASE) EMPTYSTRING = '' NL = '\n' @@ -92,13 +90,8 @@ class Parser: def _parsebody(self, container, fp): # 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' + 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 # the body as a single message. Note: any exceptions raised in the @@ -141,7 +134,20 @@ class Parser: container.preamble = preamble container.epilogue = epilogue container.add_payload(msgobj) - elif ctype == 'message/rfc822': + 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 try: |