Message204033
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? |
|
Date |
User |
Action |
Args |
2013-11-23 14:36:02 | vajrasky | set | recipients:
+ vajrasky, barry, Arfrever, r.david.murray, apollo13 |
2013-11-23 14:36:02 | vajrasky | set | messageid: <1385217362.03.0.991871262627.issue19063@psf.upfronthosting.co.za> |
2013-11-23 14:36:02 | vajrasky | link | issue19063 messages |
2013-11-23 14:36:01 | vajrasky | create | |
|