diff options
author | Barry Warsaw <barry@python.org> | 2002-04-10 21:01:31 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2002-04-10 21:01:31 (GMT) |
commit | 409a4c08b545aa064cf8fe3b8de51404756a301e (patch) | |
tree | 06cf8fe44e1fe28fbc0147635ec41961f2df6515 /Lib/email/Parser.py | |
parent | 68e69338ae19c37bd3e69cb76e107bfa76231e06 (diff) | |
download | cpython-409a4c08b545aa064cf8fe3b8de51404756a301e.zip cpython-409a4c08b545aa064cf8fe3b8de51404756a301e.tar.gz cpython-409a4c08b545aa064cf8fe3b8de51404756a301e.tar.bz2 |
Sync'ing with standalone email package 2.0.1. This adds support for
non-us-ascii character sets in headers and bodies. Some API changes
(with DeprecationWarnings for the old APIs). Better RFC-compliant
implementations of base64 and quoted-printable.
Updated test cases. Documentation updates to follow (after I finish
writing them ;).
Diffstat (limited to 'Lib/email/Parser.py')
-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 2f131d6..7177dfc 100644 --- a/Lib/email/Parser.py +++ b/Lib/email/Parser.py @@ -51,9 +51,16 @@ class Parser: lastvalue = [] lineno = 0 while 1: - line = fp.readline()[:-1] - if not line or not line.strip(): + # Don't strip the line before we test for the end condition, + # because whitespace-only header lines are RFC compliant + # continuation lines. + line = fp.readline() + if not line: break + line = line.splitlines()[0] + if not line: + break + # Ignore the trailing newline lineno += 1 # Check for initial Unix From_ line if line.startswith('From '): @@ -63,7 +70,6 @@ class Parser: else: raise Errors.HeaderParseError( 'Unix-from in headers after first rfc822 header') - # # Header continuation line if line[0] in ' \t': if not lastheader: @@ -134,11 +140,11 @@ class Parser: msgobj = self.parsestr(part) container.preamble = preamble container.epilogue = epilogue - # Ensure that the container's payload is a list - if not isinstance(container.get_payload(), ListType): - container.set_payload([msgobj]) - else: - container.add_payload(msgobj) + container.attach(msgobj) + elif container.get_main_type() == 'multipart': + # Very bad. A message is a multipart with no boundary! + raise Errors.BoundaryError( + 'multipart message with no defined boundary') 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 @@ -160,9 +166,9 @@ class Parser: except Errors.HeaderParseError: msg = self._class() self._parsebody(msg, fp) - container.add_payload(msg) + container.set_payload(msg) else: - container.add_payload(fp.read()) + container.set_payload(fp.read()) |