Форум сайта python.su
2
В общем в каком-то RFC описано что заголовки могут быть в формате:=?<code_page>?<encode_method>?<encode_text>?=
В emai.header.decode_header проверяется все это такой регуляркой:
ecre = re.compile(r''' =\? # literal =? (?P<charset>[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P<encoding>[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P<encoded>.*?) # non-greedy up to the next ?= is the encoded string \?= # literal ?= (?=[ \t]|$) # whitespace or the end of the string ''', re.VERBOSE | re.IGNORECASE | re.MULTILINE)
=?windows-1251?B?zvLi5fL7QE1haWwuUnU=?=<otvet@corp.mail.ru>
[('=?windows-1251?B?zvLi5fL7QE1haWwuUnU=?=<otvet@corp.mail.ru>', None)]
Отредактировано mironich (Июль 22, 2013 21:14:15)
Офлайн
36
python 3.3.2
from email.header import decode_header print(decode_header('=?windows-1251?B?zvLi5fL7QE1haWwuUnU=?=<otvet@corp.mail.ru>'))
[(b'\xce\xf2\xe2\xe5\xf2\xfb@Mail.Ru', 'windows-1251'), (b'<otvet@corp.mail.ru>', None)]
Офлайн