我正在解析电子邮件主题并获取多个字符串(取决于主题长度)以=?UTF-8?B?
. 这是正常行为吗?如何使用一种编码将字符串连接到一个字符串?
email_message = email.message_from_string(raw_email)
print email_message['Subject']
...
=?UTF-8?B?15bXkNeqINeR15PXmden15Qg15HXodeZ16HXmdeqINeR15vXk9eZINec15TXkdeZ158g?=
=?UTF-8?B?157Xk9eV16Ig15TXp9eZ15PXldeTINeU15bXlCDXnNeQINei15XXkdeTINeQ150g15DXoNeZINeo15U=?=
=?UTF-8?B?16nXnSDXlNeo15HXlA==?=
编辑:
subjectDecoded, encoding = decode_header(email.utils.parseaddr(email_message['Subject'])[1])[0]
if encoding==None:
subjectDecodedParsed = email_message['Subject']
print 'I am NOT decoding Subject'
print subjectDecodedParsed
else:
subjectDecodedParsed = subjectDecoded.decode(encoding)
print 'I am decoding subject'
print subjectDecodedParsed.encode('utf8') #<--- Only first line will be presented here