【发布时间】:2013-04-15 17:27:02
【问题描述】:
我从我的谷歌帐户向我的 GAE 电子邮件发送消息:
Content-Type: text/plain; charset=KOI8-R
Content-Transfer-Encoding: base64
然后使用以下代码:
logging.debug('Received personal inbound mail from: %s, to: %s, subject: %s' % (mail_message.sender, mail_message.to, mail_message.subject))
body = ''
for b in mail_message.bodies('text/plain'):
body_type, pl = b # content encoding, plain text
if pl.encoding:
body = pl.payload.decode(pl.encoding)
else:
body = pl.payload
if body:
logging.debug('Inbound personal mail body: %s' % (body))
结果我在控制台中看到以下内容:
Received personal inbound mail from: Test <test@example.com>, to: test@myappid.appspotmail.com, subject: Readable russian text
Inbound personal mail body: ������, ��� �������� ���������
即主题可读,但正文不可读。
当我检查收到的内容时,我看到以下内容:
text/plain, From nobody Mon Apr 15 17:15:34 2013
content-transfer-encoding: base64
MIME-Version: 1.0
Content-Type: text/plain; charset="koi8-r"
8NLJ18XULCDc1M8g1MXT1M/Xz8Ug08/Pwt3
如果我这样做:
body = pl.payload.decode(pl.encoding).decode('koi8-r')
然后消息正文显示正确。但是我应该如何提取编码呢?
【问题讨论】:
标签: google-app-engine email encoding python-2.5