#15249: Mangle From lines correctly when body contains invalid bytes.
Fix by Colin Su. Test by me, based on a test written by Petri Lehtinen.
diff --git a/Lib/email/generator.py b/Lib/email/generator.py
index 02487e3..c6bfb70 100644
--- a/Lib/email/generator.py
+++ b/Lib/email/generator.py
@@ -391,6 +391,8 @@
if msg._payload is None:
return
if _has_surrogates(msg._payload):
+ if self._mangle_from_:
+ msg._payload = fcre.sub(">From ", msg._payload)
self.write(msg._payload)
else:
super(BytesGenerator,self)._handle_text(msg)