Commit 5260a9bb authored by R. David Murray's avatar R. David Murray

#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.
parent cc4edd59
...@@ -220,19 +220,13 @@ class Generator: ...@@ -220,19 +220,13 @@ class Generator:
g = self.clone(s) g = self.clone(s)
g.flatten(part, unixfrom=False, linesep=self._NL) g.flatten(part, unixfrom=False, linesep=self._NL)
msgtexts.append(s.getvalue()) 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? # BAW: What about boundaries that are wrapped in double-quotes?
boundary = msg.get_boundary(failobj=self._make_boundary(alltext)) boundary = msg.get_boundary()
# If we had to calculate a new boundary because the body text if not boundary:
# contained that string, set the new boundary. We don't do it # Create a boundary that doesn't appear in any of the
# unconditionally because, while set_boundary() preserves order, it # message texts.
# doesn't preserve newlines/continuations in headers. This is no big alltext = self._encoded_NL.join(msgtexts)
# deal in practice, but turns out to be inconvenient for the unittest msg.set_boundary(self._make_boundary(alltext))
# suite.
if msg.get_boundary() != boundary:
msg.set_boundary(boundary)
# If there's a preamble, write it out, with a trailing CRLF # If there's a preamble, write it out, with a trailing CRLF
if msg.preamble is not None: if msg.preamble is not None:
self.write(msg.preamble + self._NL) self.write(msg.preamble + self._NL)
......
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