I'm using imaplib
to fetch subjects of email messages from Gmail, and some of the subjects look like this:
=?utf-8?Q?12_=D7=A1=D7=91=D7=99=D7=97?=
How can I decode this representation into a normal Unicode text?
Thanks in advance!
Your string is encoded using the 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 סביח
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With