Commit b1c1de38 authored by Barry Warsaw's avatar Barry Warsaw

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).
parent 356afac4
...@@ -8,11 +8,17 @@ import time ...@@ -8,11 +8,17 @@ import time
import re import re
import random import random
from types import ListType, StringType from types import ListType
from cStringIO import StringIO from cStringIO import StringIO
from email.Header import Header from email.Header import Header
try:
from email._compat22 import _isstring
except SyntaxError:
from email._compat21 import _isstring
EMPTYSTRING = '' EMPTYSTRING = ''
SEMISPACE = '; ' SEMISPACE = '; '
BAR = '|' BAR = '|'
...@@ -187,7 +193,7 @@ class Generator: ...@@ -187,7 +193,7 @@ class Generator:
cset = msg.get_charset() cset = msg.get_charset()
if cset is not None: if cset is not None:
payload = cset.body_encode(payload) payload = cset.body_encode(payload)
if not isinstance(payload, StringType): if not _isstring(payload):
raise TypeError, 'string payload expected: %s' % type(payload) raise TypeError, 'string payload expected: %s' % type(payload)
if self._mangle_from_: if self._mangle_from_:
payload = fcre.sub('>From ', payload) payload = fcre.sub('>From ', payload)
...@@ -209,6 +215,10 @@ class Generator: ...@@ -209,6 +215,10 @@ class Generator:
print >> self._fp, '\n' print >> self._fp, '\n'
print >> self._fp, '--' + boundary + '--' print >> self._fp, '--' + boundary + '--'
return 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): elif not isinstance(subparts, ListType):
# Scalar payload # Scalar payload
subparts = [subparts] subparts = [subparts]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment