IMAP SEARCH complex query
Asked Answered
U

1

6

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?

Umbles answered 25/10, 2011 at 8:56 Comment(0)
L
6

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

Ludwigg answered 25/10, 2011 at 12:3 Comment(1)
Just a quick correction - IMAP does not use reverse polish notation (which would be more like: "somestring" BODY "[email protected]" TO "[email protected]" FROM OR AND) but simply polish (or prefix) notation. IMAP's design is based on LISP, from what I can gather.Quad

© 2022 - 2024 — McMap. All rights reserved.