Vajrasky Kok added the comment: R. David Murray, your patch fails with this situation:
from email.mime.nonmultipart import * from email.charset import * from email.message import Message from io import BytesIO from email.generator import BytesGenerator msg = Message() cs = Charset('utf-8') cs.body_encoding = None msg.set_payload('АБВ', cs) msg.as_string() fp = BytesIO() g = BytesGenerator(fp) g.flatten(msg) print(fp.getvalue()) ===> b'MIME-Version: 1.0\nContent-Type: text/plain; charset="utf-8"\nContent-Transfer-Encoding: base64\n\n0JDQkdCS\n' Apparently, there is a funky bug. If you never call msg.as_string(), the fp.get_value() will output correctly: b'MIME-Version: 1.0\nContent-Type: text/plain; charset="utf-8"\nContent-Transfer-Encoding: 8bit\n\n\xd0\x90\xd0\x91\xd0\x92' It turns out that msg.as_string() calls set_payload with different kind of charset! Attached the patch to solve this problem. Not sure whether this is important or not to fix in 3.3. How many people call bytes generator after calling string generator? ---------- Added file: http://bugs.python.org/file32800/support_8bit_charset_cte_v2.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19063> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com