#11554: reactivate test_email_codecs, and make it pass.
The fix is to charset.py, which was not doing the encoding to the
correct output character set when doing a body_encode for either
the shift-jis or euc-jp charsets. There's also a fix for handling
a bytes input in encoders.py.
Patch by Michael Henry, comment changes by me.
diff --git a/Lib/email/charset.py b/Lib/email/charset.py
index 24d5545..f22be2c 100644
--- a/Lib/email/charset.py
+++ b/Lib/email/charset.py
@@ -263,7 +263,7 @@
Returns "quoted-printable" if self.body_encoding is QP.
Returns "base64" if self.body_encoding is BASE64.
- Returns "7bit" otherwise.
+ Returns conversion function otherwise.
"""
assert self.body_encoding != SHORTEST
if self.body_encoding == QP:
@@ -381,7 +381,10 @@
"""Body-encode a string by converting it first to bytes.
The type of encoding (base64 or quoted-printable) will be based on
- self.body_encoding.
+ self.body_encoding. If body_encoding is None, we assume the
+ output charset is a 7bit encoding, so re-encoding the decoded
+ string using the ascii codec produces the correct string version
+ of the content.
"""
# 7bit/8bit encodings return the string unchanged (module conversions)
if self.body_encoding is BASE64:
@@ -391,4 +394,6 @@
elif self.body_encoding is QP:
return email.quoprimime.body_encode(string)
else:
+ if isinstance(string, str):
+ string = string.encode(self.output_charset).decode('ascii')
return string