MBOX-Line: From arnt at gulbrandsen.priv.no  Thu Jan 29 12:18:56 2009
To: imap-protocol@u.washington.edu
From: Arnt Gulbrandsen <arnt@gulbrandsen.priv.no>
Date: Fri Jun  8 12:34:42 2018
Subject: [Imap-protocol] SEARCH OR question
In-Reply-To: <4981FBC7.9040509@sun.com>
References: <4981FBC7.9040509@sun.com>
Message-ID: <Km78hblRL25Kbh6zGDPK8w.md5@lochnagar>

Bill Shannon writes:
> What's the correct syntax to do a SEARCH for an OR of three terms?
> I've been using:
>
> SEARCH OR OR HEADER Message-ID id1 HEADER Message-ID id2 HEADER 
> Message-ID id3

That's the right way.

> RFC 3501 says:
>
>       When multiple keys are specified, the result is the intersection
>       (AND function) of all the messages that match those keys.

It's trying to say "if you want OR, you have to say OR. If you want AND, 
you're in luck because that's default".

> How would this work with OR?
>
> SEARCH OR (HEADER Message-ID id1 HEADER Message-ID id2 HEADER Message-ID id3)

That one isn't syntactically valid since there's only one search term after OR.

(a and b) or c would be "OR (a b) c" or "OR c (a b)".

> Are the multiple terms inside the parens combined using OR because they're
> part of an OR key?

No.

> Or are they combined with AND because they're multiple
> keys (first rule above)?

Yes.

> Assuming the first syntax at the top is correct, it appears that Exchange
> 2003 fails with more than two terms in OR.

Can't have more than two terms in an OR. IF you want three, you have to 
have two ORs.

This command ORs together 14 search terms and ANDs the result of that 
with a single search term:

7pq uid search return () or or or from @spielzeughausen header 
"Resent-From" @spielzeughausen or header Sender @spielzeughausen header 
"Resent-Sender" @spielzeughausen or or or header "Return-Path" 
@spielzeughausen header "Reply-To" @spielzeughausen or To 
@spielzeughausen Cc @spielzeughausen or or header Bcc @spielzeughausen 
header "Resent-To" @spielzeughausen or header "Resent-Cc" 
@spielzeughausen header "Resent-Bcc" @spielzeughausen since 01-dec-2008

Arnt

