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 talking to IMAP servers, check with IMAP RFC.
You must remove extra quotes, and you must not encode the strings. Also, charset specifies the charset of the search query, not the charset of the message header. This should work (works for me):
M.search("utf-8", "(SUBJECT %s)" % u"réception".encode("utf-8"))
# this also works:
M.search("iso8859-1", "(SUBJECT %s)" % u"réception".encode("iso8859-1"))
Edit:
Apparently some servers (at least gmail as of August 2013) support utf-8 strings only when sent as literals. Python imaplib has a very limited literal arguments support, the best one can do is something like:
term = u"réception".encode("utf-8")
M.literal = term
M.search("utf-8", "SUBJECT")