Tell me how to translate this string into a readable form:
=?windows-1251?Q?=EC=E5=ED=F2=2Etxt?= Original line
ΠΌΠ΅Π½Ρ.txt Tell me how to translate this string into a readable form:
=?windows-1251?Q?=EC=E5=ED=F2=2Etxt?= Original line
ΠΌΠ΅Π½Ρ.txt The email.header module will help you .
import email.header a = "=?windows-1251?Q?=EC=E5=ED=F2=2Etxt?=" print email.header.decode_header(a) The string you quoted is encoded according to RFC2047 . That is, the format of the line is:
=?ΠΊΠΎΠ΄ΠΈΡΠΎΠ²ΠΊΠ°?ΠΏΡΠΈΠ·Π½Π°ΠΊ ΡΠΈΠΏΠ° ΠΊΠΎΠ΄ΠΈΡΠΎΠ²Π°Π½ΠΈΡ?Π·Π°ΠΊΠΎΠ΄ΠΈΡΠΎΠ²Π°Π½Π½Π°Ρ ΡΡΡΠΎΠΊΠ°?= The signs of the type of coding are known two Q and B Accordingly, they signify QuotedPrintable and Base64 encoding, respectively.
decode_header() accepts a string in RFC2047 format, recognizes the encoding type, decodes and returns two parameters β the decoded string and encoding.
decode() : [(data, encoding)] = decode_header('=?windows-1251?Q?=EC=E5=ED=F2=2Etxt?='); print(data.decode(encoding)) [(data, encoding)] = decode_header('=?windows-1251?Q?=EC=E5=ED=F2=2Etxt?='); print(data.decode(encoding)) - jfss = '=?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu>' , then email.header.make_header() convenient to use: h = make_header(decode_header(s)) . And to get the text = unicode(h) : text = unicode(h) or on Python 3: text = str(h) (you can directly print print(h) ). - jfs import quopri a = '=EC=E5=ED=F2=2E' b = quopri.decodestring(a) print(b.decode('windows-1251')) Source: https://ru.stackoverflow.com/questions/542392/
All Articles