summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-07-23 02:32:44 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-07-23 02:32:44 (GMT)
commit7e918cfe2805f4556995885a14e684029c7c95ba (patch)
tree6ae529309f4a91bb7e1d1cff9abdaac792076a10
parent28a9f2193ade4e0f12d3110d2f199b07f342eff8 (diff)
parent6a31bc6d81f42ac39868ced08d83cad880a7cce6 (diff)
downloadcpython-7e918cfe2805f4556995885a14e684029c7c95ba.zip
cpython-7e918cfe2805f4556995885a14e684029c7c95ba.tar.gz
cpython-7e918cfe2805f4556995885a14e684029c7c95ba.tar.bz2
merge heads.
-rw-r--r--Lib/email/generator.py12
-rw-r--r--Lib/email/test/test_email.py22
-rw-r--r--Misc/NEWS3
3 files changed, 35 insertions, 2 deletions
diff --git a/Lib/email/generator.py b/Lib/email/generator.py
index 04c0210..02487e3 100644
--- 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)
+ if self._mangle_from_:
+ preamble = fcre.sub('>From ', msg.preamble)
+ else:
+ preamble = msg.preamble
+ self.write(preamble + self._NL)
# dash-boundary transport-padding CRLF
self.write('--' + boundary + self._NL)
# body-part
@@ -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)
+ if self._mangle_from_:
+ epilogue = fcre.sub('>From ', msg.epilogue)
+ else:
+ epilogue = msg.epilogue
+ self.write(epilogue)
def _handle_multipart_signed(self, msg):
# The contents of signed parts has to stay unmodified in order to keep
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index 65b3ebd..95dc4af 100644
--- 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()
+ g = Generator(s, mangle_from_=True)
+ msg = email.message_from_string(textwrap.dedent("""\
+ From: foo@bar.com
+ Mime-Version: 1.0
+ Content-Type: multipart/mixed; boundary=XXX
+
+ From somewhere unknown
+
+ --XXX
+ Content-Type: text/plain
+
+ foo
+
+ --XXX--
+
+ From somewhere unknowable
+ """))
+ g.flatten(msg)
+ self.assertEqual(len([1 for x in s.getvalue().split('\n')
+ if x.startswith('>From ')]), 2)
# Test the basic MIMEAudio class
diff --git a/Misc/NEWS b/Misc/NEWS
index d8a581b..ff7be30 100644
--- 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
+ lines that start with 'From' that occur in a MIME preamble or epilogue.
+
- Issue #13922: argparse no longer incorrectly strips '--'s that appear
after the first one.