Python IMAP search using a subject encoded with iso-8859-1
From a different account, I sent myself an email with the subject Test de réception en local . Now using IMAP, I want to find that email searching by subject. When doing a search for ALL and finding the email among the output, I see: Subject: =?ISO-8859-1?Q?Test_de_r=E9ception_en_local?= So now, searching with imap, I try: M = imaplib.IMAP4_SSL('imap.gmail.com', 993) M.login('user@gmail.com', 'password') M.select('[Gmail]/All Mail') subject = Header(email_model.subject, 'iso-8859-1').encode() #email_model.subject is in unicode, utf-8 encoded typ, data = M.search('iso-8859-1', '(SUBJECT "%s")'