Getting the issue "BAD Command Argument Error" when searching outlook email by using criterias
I'm using the IMAP search function to fetch the uids of the outlook emails with the host is outlook.office365.com
imap.search([ [ "OR", [ "FROM", "[email protected]" ], [ "OR", [ "FROM", "[email protected]" ], [ "OR", [ "FROM", "[email protected]" ], [ "OR", [ "FROM", "[email protected]" ], [ "OR", [ "FROM", "[email protected]" ], [ "FROM", "[email protected]" ] ] ] ] ] ] ], function (err, results) {}
But I'm facing the error
<= 'A5 OK [READ-ONLY] EXAMINE completed.' imap/index.js:16 => 'A6 UID SEARCH OR (FROM "[email protected]") (OR (FROM "[email protected]") (OR (FROM "[email protected]") (OR (FROM "[email protected]") (OR (FROM "[email protected]") (FROM "[email protected]")))))' imap/index.js:16 <= 'A6 BAD Command Argument Error. 12'
This error occurs when criteria have more than 4 OR level, It's only worked fine with <= 4 OR level. I tested the same criteria above for Icloud, other mails and it's worked fine.
That's not entirely surprising, Outlook/Exchange IMAP servers always seem to have issues with IMAP compatibility and wonky behavior. There's nothing this module can do unfortunately, you'll just have to break up your searches in this case.
Thanks, @mscdex, I split it up into several parts. When I search SENT path for 10 accounts, I will create 10 requests to the server because the SENT path will contain criteria TO, CC, BCC (at least 3 OR level) so performance will be reduced significantly. Maybe I should accept it.