由于当电子邮件主题为 UTF-8 编码时,标准 GAE 的电子邮件功能出现问题,因此我尝试手动处理它:
msg_encoding = self.request.headers['Content-Type'].split('charset=')[1] # message/rfc822; charset=UTF-8
msg = email.message_from_string(self.request.body)
if msg:
logging.debug(msg.get_content_charset()) # None
logging.debug(msg['to'])
logging.debug(msg['from'])
logging.debug(msg['Subject'].decode(msg_encoding))
我做对了吗?我应该解码主题吗?还是由电子邮件解析器自动完成?