I'm trying to find mails matching a particular FROM address. I've looked at this answer but it doesn't work for me.
Here's the relevant code:
import imaplib
conn = imaplib.IMAP4_SSL(IMAPserver)
conn.login(IMAPuserName, IMAPpassword)
retVal, data = conn.select("INBOX")
if retVal != "OK":
<PRINT SOME ERROR MESSAGE>
sys.exit(1)
All this works. Here are some variations of the search command that don't work:
retVal, data = conn.search(None, 'UNSEEN HEADER FROM "foo@example.com"')
retVal, data = conn.search(None, 'UNSEEN FROM "foo@example.com"')
retVal, data = conn.search(None, 'FROM "foo@example.com"')
retVal, data = conn.search(None, 'HEADER FROM "foo@example.com"')
All of these result in errors like these:
imaplib.error: SEARCH command error: BAD ['Error in IMAP command SEARCH:
Unexpected string as search key: FROM "foo@example.com"']
I've referred to the relevant section of the IMAP v4 RFC but I can't figure out what exactly I'm doing wrong. Any help would be greatly appreciated.