]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
_handle_multipart(): Fixes for SF bug #531966. Specifically two
authorBarry Warsaw <barry@python.org>
Fri, 22 Mar 2002 16:21:56 +0000 (16:21 +0000)
committerBarry Warsaw <barry@python.org>
Fri, 22 Mar 2002 16:21:56 +0000 (16:21 +0000)
situations are handled now: a multipart/* containing no payload
(i.e. never set), and a multipart/* containing a scalar payload
(i.e. Message.add_payload() having been called exactly once, not
passing in a sequence object).

_make_boundary(): Fixed bogus cut-n-paste error (self as first arg).

I will merge these changes into the standalone email package and
Python 2.3 separately.

Lib/email/Generator.py

index e969d00d89ed19792f4ba48fe5ab1b3facb9e4dd..8849d20ae489df6579098579b87de18f00b75a2a 100644 (file)
@@ -237,7 +237,20 @@ class Generator:
         # together, and then make sure that the boundary we've chosen isn't
         # present in the payload.
         msgtexts = []
-        for part in msg.get_payload():
+        # BAW: kludge for broken add_payload() semantics; watch out for
+        # multipart/* MIME types with None or scalar payloads.
+        subparts = msg.get_payload()
+        if subparts is None:
+            # Nothing has every been attached
+            boundary = msg.get_boundary(failobj=_make_boundary())
+            print >> self._fp, '--' + boundary
+            print >> self._fp, '\n'
+            print >> self._fp, '--' + boundary + '--'
+            return
+        elif not isinstance(subparts, ListType):
+            # Scalar payload
+            subparts = [subparts]
+        for part in subparts:
             s = StringIO()
             g = self.__class__(s, self._mangle_from_, self.__maxheaderlen)
             g(part, unixfrom=0)
@@ -369,7 +382,7 @@ class DecodedGenerator(Generator):
 
 \f
 # Helper
-def _make_boundary(self, text=None):
+def _make_boundary(text=None):
     # Craft a random boundary.  If text is given, ensure that the chosen
     # boundary doesn't appear in the text.
     boundary = ('=' * 15) + repr(random.random()).split('.')[1] + '=='