I'm trying to make complex IMAP search query using bare python imaplib
.
The query is pretty much simple I have a list of emails and I'm trying to query all messages with thoses adresses.
A simple query may look like this:
[
['OR',
['FROM', 'email1@domain.com'],
['OR',
['FROM', 'email2@domain.com'],
['FROM', 'email3@domain.com']
]]]
But when I began to make this kind of query with large set of addresses (more thant 5) I get:
SEARCH command error: BAD [b'Command Argument Error. 12']
Does the IMAP protocol have such limitation? Maybe because of the complexity of the query? Or is the max imbrication layer?
My references or:
imaplib
library: https://docs.python.org/3/library/imaplib.html IMAP Query limitations may be on your email server side. This is independent of imaplib.
You can try to use IMAP query builder from my lib: https://github.com/ikvk/imap_tools
It can helps to build such queries much easier.
For example, i have successfully try to do this at (YANDEX, ZIMBRA, OUTLOOK, GOOGLE):
from imap_tools import MailBox, OR
with MailBox('imap.mail.com').login('test@mail.com', 'pwd') as mailbox:
for msg in mailbox.fetch(OR(from_=['1@a','2@a','3@a','4@a','5@a','6@a','hello@ya.ru'])):
print(msg.date)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.