#16564: Fix regression in use of encoders.encode_noop with binary data.
diff --git a/Lib/email/encoders.py b/Lib/email/encoders.py
index e5c099f..88b2f57 100644
--- a/Lib/email/encoders.py
+++ b/Lib/email/encoders.py
@@ -76,3 +76,9 @@
def encode_noop(msg):
"""Do nothing."""
+ # Well, not quite *nothing*: in Python3 we have to turn bytes into a string
+ # in our internal surrogateescaped form in order to keep the model
+ # consistent.
+ orig = msg.get_payload()
+ if not isinstance(orig, str):
+ msg.set_payload(orig.decode('ascii', 'surrogateescape'))