How to decode this unicode string representation in Python?

I use imaplib to retrieve email themes from Gmail, and some of them look like this:

 =?utf-8?Q?12_=D7=A1=D7=91=D7=99=D7=97?= 

How can I decode this representation into plain Unicode text?

Thanks in advance!

+4
source share
1 answer

Your string is encoded in Quoted-printable format for MIME headers. The email.header module handles this for you:

 >>> from email.header import decode_header >>> for part in decode_header('=?utf-8?Q?12_=D7=A1=D7=91=D7=99=D7=97?='): ... print(str(*part)) 12 סביח 
+13
source

Source: https://habr.com/ru/post/1435464/


All Articles