summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-12-12 20:06:19 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2010-12-12 20:06:19 (GMT)
commit5260a9bbdcc665a3e77316552f020a2c7ef28594 (patch)
treed2674f0824815f550a83a3208917f00a98372ebe
parentcc4edd59d65f6c1c31d1331a0a61681c09bb43dc (diff)
downloadcpython-5260a9bbdcc665a3e77316552f020a2c7ef28594.zip
cpython-5260a9bbdcc665a3e77316552f020a2c7ef28594.tar.gz
cpython-5260a9bbdcc665a3e77316552f020a2c7ef28594.tar.bz2
#243654: only create a new MIME boundary if we don't already have one.
The rearranged code should do exactly what the old code did, but the new code avoids a potentially costly re computation in the case where a boundary already exists.
-rw-r--r--Lib/email/generator.py18
1 files changed, 6 insertions, 12 deletions
diff --git a/Lib/email/generator.py b/Lib/email/generator.py
index 086cf4b..510f68b 100644
--- a/Lib/email/generator.py
+++ b/Lib/email/generator.py
@@ -220,19 +220,13 @@ class Generator:
g = self.clone(s)
g.flatten(part, unixfrom=False, linesep=self._NL)
msgtexts.append(s.getvalue())
- # Now make sure the boundary we've selected doesn't appear in any of
- # the message texts.
- alltext = self._encoded_NL.join(msgtexts)
# BAW: What about boundaries that are wrapped in double-quotes?
- boundary = msg.get_boundary(failobj=self._make_boundary(alltext))
- # If we had to calculate a new boundary because the body text
- # contained that string, set the new boundary. We don't do it
- # unconditionally because, while set_boundary() preserves order, it
- # doesn't preserve newlines/continuations in headers. This is no big
- # deal in practice, but turns out to be inconvenient for the unittest
- # suite.
- if msg.get_boundary() != boundary:
- msg.set_boundary(boundary)
+ boundary = msg.get_boundary()
+ if not boundary:
+ # Create a boundary that doesn't appear in any of the
+ # message texts.
+ alltext = self._encoded_NL.join(msgtexts)
+ msg.set_boundary(self._make_boundary(alltext))
# If there's a preamble, write it out, with a trailing CRLF
if msg.preamble is not None:
self.write(msg.preamble + self._NL)