2

Imaplib search function throws an exception

"SEARCH command error: BAD [b'Could not parse command']"

as soon as I use a character with a french accent, like é, è or à.

Here is my code:

import imaplib

imap_conn = imaplib.IMAP4_SSL('imap.gmail.com')
imap_conn.login(login, password)
imap_conn.select()
typ, mail_ids = imap_conn.search(
    "utf-8",
    '(SUBJECT "bonne année")'.encode('utf-8'))

If I search "bonne annee", I have no exception and the search function returns IDs.

Do you know what I should modify?

I saw examples setting imap_conn.literal, and then calling imap_conn.search("utf-8", "SUBJECT"). I agree to use this solution, but what I search look like (FROM "myaddress@gmail.com" SUBJECT "bonne annee" SINCE "01-Dec-2021") and I did not found how to use literal with several criteria. If somebody has the solution, I am interested!

Thank!

Nono
  • 21
  • 2

0 Answers0