From 5516c7b319999cb7beb4bc1f7d07459e4390e852 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 22 Mar 2002 16:21:56 +0000 Subject: [PATCH] _handle_multipart(): Fixes for SF bug #531966. Specifically two 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 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Lib/email/Generator.py b/Lib/email/Generator.py index e969d00d89ed..8849d20ae489 100644 --- a/Lib/email/Generator.py +++ b/Lib/email/Generator.py @@ -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): # 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] + '==' -- 2.47.3