New submission from Dongying Zhang <zhangdongying1...@gmail.com>: The as_string method in mime classes in module email.mime use base64 to encode the text, but segmentedly while the text contents non-acsii characters and is in type of unicode. This behavior confuse some of the email servers. For example: =================================================================== #-*- coding: utf-8 -*- import base64 from email.mime.text import MIMEText content = u'''Hello: 这是一封测试邮件. Please remove this message after reading, and I hope this won't bother you for a long time ''' m = MIMEText(content, 'plain', 'utf-8') print m.as_string() m = MIMEText(content.encode('utf-8'), 'plain', 'utf-8') print m.as_string() print base64.encodestring(content.encode('utf-8')) =================================================================== The first as_string method gives: ------------------------------------------------------------------- SGVsbG86CiAgICDov5nmmK/kuIDlsIHmtYvor5Xpgq7ku7YuCiAgIFBsZWFzZSByZW1vdmUgdGhpcyBtZXNzYWdlIGFmdGVyIA== cmVhZGluZywKICAgYW5kIEkgaG9wZSB0aGlzIHdvbid0IGJvdGhlciB5b3UgZm9yIGEgbG9uZyB0 aW1lCg== ------------------------------------------------------------------- Please notice that there is a '==' at the end of the first line. The output of both the second as_string and base64.encodestring method maybe more appropriate, which is: ------------------------------------------------------------------- SGVsbG86CiAgICDov5nmmK/kuIDlsIHmtYvor5Xpgq7ku7YuCiAgIFBsZWFzZSByZW1vdmUgdGhp cyBtZXNzYWdlIGFmdGVyIHJlYWRpbmcsCiAgIGFuZCBJIGhvcGUgdGhpcyB3b24ndCBib3RoZXIg eW91IGZvciBhIGxvbmcgdGltZQo=
---------- components: IO files: test.py messages: 100380 nosy: zhangdongying severity: normal status: open title: "as_string" method in email's mime objects encode text segmentedly type: behavior versions: Python 2.6 Added file: http://bugs.python.org/file16428/test.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue8054> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com