FAP Encoding for IMAP

I am trying to get some emails from gmail using imap like this

"(BODY.PEEK[HEADER.FIELDS (subject from date)] X-GM-MSGID X-GM-LABELS X-GM-THRID)"

The problem is that it does not work with special and accented characters. For instance,

Stรฉphane Maniaci

displayed as

=?ISO-8859-1?Q?St=E9phane_Maniaci?=

How to tell Gmail about the return of encoding strings of my choice, let's say I want Charset to be UTF-8.

How to configure this in the IMAP command mentioned above?

+1
source share
1 answer

Good. I found out that email.utils can help a lot here.

It has methods for analyzing date, email, and any other information from imap messages.

It also has methods for decoding imap strings. Like this

from email.header import decode_header
value, charset = decode_header(string_to_be_decoded)
+4

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


All Articles