diff options
author | Barry Warsaw <barry@python.org> | 2002-09-10 16:13:45 +0000 |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2002-09-10 16:13:45 +0000 |
commit | da6a5573040bef1ac530291a1ace99c9471ff043 (patch) | |
tree | cd982a732660e22474f42c37f5e057e7fa48a474 | |
parent | d5b571a2b50798b7d73fb4c4ba6ebc88a3704e75 (diff) | |
download | cpython-da6a5573040bef1ac530291a1ace99c9471ff043.tar.gz |
Import _isstring() from the compatibility layer.
_handle_text(): Use _isstring() for stringiness test.
_handle_multipart(): Add a test before the ListType test, checking for
stringiness of the payload. String payloads for multitypes means a
message with broken MIME chrome was parsed by a lax parser. Instead
of raising a BoundaryError in those cases, the entire body is assigned
to the message payload (but since the content type is still
multipart/*, the Generator needs to be updated too).
-rw-r--r-- | Lib/email/Generator.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/email/Generator.py b/Lib/email/Generator.py index 8ce380725d..e8bce102ad 100644 --- a/Lib/email/Generator.py +++ b/Lib/email/Generator.py @@ -8,11 +8,17 @@ import time import re import random -from types import ListType, StringType +from types import ListType from cStringIO import StringIO from email.Header import Header +try: + from email._compat22 import _isstring +except SyntaxError: + from email._compat21 import _isstring + + EMPTYSTRING = '' SEMISPACE = '; ' BAR = '|' @@ -187,7 +193,7 @@ class Generator: cset = msg.get_charset() if cset is not None: payload = cset.body_encode(payload) - if not isinstance(payload, StringType): + if not _isstring(payload): raise TypeError, 'string payload expected: %s' % type(payload) if self._mangle_from_: payload = fcre.sub('>From ', payload) @@ -209,6 +215,10 @@ class Generator: print >> self._fp, '\n' print >> self._fp, '--' + boundary + '--' return + elif _isstring(subparts): + # e.g. a non-strict parse of a message with no starting boundary. + self._fp.write(subparts) + return elif not isinstance(subparts, ListType): # Scalar payload subparts = [subparts] |