cpython: b97f65f2298d (original) (raw)
Mercurial > cpython
changeset 78245:b97f65f2298d 3.2
#15232: correctly mangle From lines in MIME preamble and epilogue [#15232]
R David Murray rdmurray@bitdance.com | |
---|---|
date | Sun, 22 Jul 2012 21:47:53 -0400 |
parents | 84b577567fab |
children | 80b81658455b af2e044609ca |
files | Lib/email/generator.py Lib/email/test/test_email.py Misc/NEWS |
diffstat | 3 files changed, 35 insertions(+), 2 deletions(-)[+] [-] Lib/email/generator.py 12 Lib/email/test/test_email.py 22 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/email/generator.py +++ b/Lib/email/generator.py @@ -233,7 +233,11 @@ class Generator: msg.set_boundary(boundary) # If there's a preamble, write it out, with a trailing CRLF if msg.preamble is not None:
self.write(msg.preamble + self._NL)[](#l1.7)
if self._mangle_from_:[](#l1.8)
preamble = fcre.sub('>From ', msg.preamble)[](#l1.9)
else:[](#l1.10)
preamble = msg.preamble[](#l1.11)
self.write(preamble + self._NL)[](#l1.12) # dash-boundary transport-padding CRLF[](#l1.13) self.write('--' + boundary + self._NL)[](#l1.14) # body-part[](#l1.15)
@@ -251,7 +255,11 @@ class Generator: self.write(self._NL + '--' + boundary + '--') if msg.epilogue is not None: self.write(self._NL)
self.write(msg.epilogue)[](#l1.20)
if self._mangle_from_:[](#l1.21)
epilogue = fcre.sub('>From ', msg.epilogue)[](#l1.22)
else:[](#l1.23)
epilogue = msg.epilogue[](#l1.24)
self.write(epilogue)[](#l1.25)
def _handle_multipart_signed(self, msg): # The contents of signed parts has to stay unmodified in order to keep
--- a/Lib/email/test/test_email.py +++ b/Lib/email/test/test_email.py @@ -1275,6 +1275,28 @@ From the desk of A.A.A.: Blah blah blah """)
- def test_mangle_from_in_preamble_and_epilog(self):
s = StringIO()[](#l2.8)
g = Generator(s, mangle_from_=True)[](#l2.9)
msg = email.message_from_string(textwrap.dedent("""\[](#l2.10)
From: foo@bar.com[](#l2.11)
Mime-Version: 1.0[](#l2.12)
Content-Type: multipart/mixed; boundary=XXX[](#l2.13)
From somewhere unknown[](#l2.15)
--XXX[](#l2.17)
Content-Type: text/plain[](#l2.18)
foo[](#l2.20)
--XXX--[](#l2.22)
From somewhere unknowable[](#l2.24)
"""))[](#l2.25)
g.flatten(msg)[](#l2.26)
self.assertEqual(len([1 for x in s.getvalue().split('\n')[](#l2.27)
if x.startswith('>From ')]), 2)[](#l2.28)
Test the basic MIMEAudio class
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -98,6 +98,9 @@ Core and Builtins Library ------- +- Issue #15232: when mangle_from is True, email.Generator now correctly mangles