'C# EWS O365 Get eMail using Searchfilter with or

i want to search mails and have several filters. As far as i noticed all filters are connected using "and" so all filters have to be valid. Is there something to use filters with "or"?

searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Test"));
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Body, "socks"));
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.Sender, "[email protected]"));

OR

searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Test"));
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Body, "socks"));
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.Sender, "[email protected]"));

Do i have to start two different searches or is there something like

(
 ( filter1 ) and
 ( filter2 ) and
 ( ( filter3a ) or ( filter3b ) )
)

I read docs.microsoft.com https://docs.microsoft.com/de-de/exchange/client-developer/exchange-web-services/how-to-use-search-filters-with-ews-in-exchange?msclkid=a2ee168fab7711ec971951bfdcbc8e44

but i couldn't find the answer.

So far i only tried more than one search to get the mails. Result for one "or" was okay but if there are more than one "or" you get lost in the code.



Solution 1:[1]

You can nest SearchFilter collections so in your example the

( ( filter3a ) or ( filter3b ) )

would be a SearchFilterCollection the implements or so the And would only be fulfilled if one of the two Or filters are true eg to make it or you just do that using the constructor

SearchFilter.SearchFilterCollection nestedSearchFilterCollection =
new SearchFilter.SearchFilterCollection(LogicalOperator.Or);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Glen Scales