Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search imap inbox with mailkit based on multiple condition?

I want to search imap inbox with mailkit based on multiple condition like NotSeen & NotDeleted. I know the queries are receptively,if we do individual search query.

var uids = client.Inbox.Search(SearchQuery.NotSeen); 
var uids = client.Inbox.Search(SearchQuery.NotDeleted );   

but i need to put those two queries together & get all Uids based on the conditions. Any help would be appreciated.

like image 276
aspdotnetdevelopertest Avatar asked Oct 22 '25 16:10

aspdotnetdevelopertest


2 Answers

You can combine search queries using the And() and/or Or():

var uids = client.Inbox.Search (SearchQuery.NotSeen.And (SearchQuery.NotDeleted));

or

var uids = client.Inbox.Search (SearchQuery.And (SearchQuery.NotSeen, SearchQuery.NotDeleted));
like image 58
jstedfast Avatar answered Oct 25 '25 06:10

jstedfast


This snippet adds an conditional search condition after the main query has been set

var query = MailKit.Search.SearchQuery.FromContains("[email protected]")
                            .And(MailKit.Search.SearchQuery.SubjectContains("Your Subject"));

query = query .And(MailKit.Search.SearchQuery.DeliveredAfter(DateTime.Parse("2020-02-28")));
like image 27
tnorris Avatar answered Oct 25 '25 06:10

tnorris