Dipanshu Tyagi
Dipanshu Tyagi

Reputation: 15

imaplib.IMAP4.error: SEARCH command error: BAD [b'The specified message set is invalid.'] , not able search with multiple filter's

mail.select("INBOX")
result, messages = mail.search(None, '(AND ("UNSEEN") ("SUBJECT" "important") ("FROM" "[email protected]"))')

When I use OR instead of AND it works fine but when I change it I get this error:

imaplib.IMAP4.error: SEARCH command error: BAD [b'The specified message set is invalid.']

How can I filter muliple fields, like when there are multiple mailIds to filter?

Currntly I am using this:

mail.search(None,'UNSEEN' ,'FROM','"[email protected]"')

with this quary i am not able to filter mulitple From and wants to perform AND OR operations

Versions:

Let me know if you need any extra information.

Upvotes: 0

Views: 36

Answers (1)

arnt
arnt

Reputation: 9675

You're just guessing at the AND syntax, right?

The defined AND syntax is (strangely) just a parenthesised list of terms. What you want is something like (UNSEEN SUBJECT "important" FROM "[email protected]").

Upvotes: 1

Related Questions