Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IMAP SEARCH complex query

I need to find all mails in IMAP mailbox which contains somestring in BODY and is FROM [email protected] or TO [email protected].

Trying to do:

49:51.53 > JBPM3 SEARCH CHARSET utf-8 "BODY \"somestring\" (OR (TO \"[email protected]\") (FROM \"[email protected]\"))"

Receiving:

49:51.71 < JBPM3 BAD Could not parse command

How to make it work using GMail?

like image 848
Oleksandr Avatar asked Oct 25 '11 08:10

Oleksandr


1 Answers

You may skip parenthesis '(' ')' to group logical expressions in IMAP. Parenthesis are not needed in Polish Notation (see edit below):

A0001 SEARCH CHARSET utf-8 BODY "somestring" OR TO "[email protected]" FROM "[email protected]"

You could also use gmail search syntax (X-GM-RAW) command: http://www.limilabs.com/blog/search-gmail-using-gmails-search-syntax

[Edit] Parenthesis are sometimes required in IMAP SEARCH. This is because AND operator can have more than 2 operands and is not explicitly defined: http://www.limilabs.com/blog/imap-search-requires-parentheses

like image 118
Pawel Lesnikowski Avatar answered Sep 22 '22 19:09

Pawel Lesnikowski