我在python-milter中从MIME消息中提取文件,遇到了这样的文件问题:
=?ISO-8859-1?问?Certificado=5fZonifaci=F3n=5F2010=2Epdf?=
我好像不能把这个名字解码成UTF。为了解决以前的ISO-8859-1问题,我开始将所有文件名传递给此函数:
def unicodeConvert(self, fname):
normalized = False
while normalized == False:
try:
fname = unicodedata.normalize('NFKD', unicode(fname, 'utf-8')).encode('ascii', 'ignore')
normalized = True
except UnicodeDecodeError:
fname = fname.decode('iso-8859-1')#.encode('utf-8')
normalized = True
except UnicodeError:
fname = unicode(fname.content.strip(codecs.BOM_UTF8), 'utf-8')
normalized = True
except TypeError:
fname = fname.encode('utf-8')
return fname
在我找到这个文件名之前一直有效。在
我们一如既往地欣赏创意。在
您的字符串使用MIME头的Quoted-printable格式进行编码。^{} module 为您处理此问题:
相关问题 更多 >
编程相关推荐