MailKit can't search James' old emails?

58 Views Asked by At

Development environment: C#, Core 3.1, MailKit 3.5.0, Apache James 3.3.0

Using the same code, after restarting the James service, the old emails will not be found.

using (var imapClient = new ImapClient())
{
    var sent = imapClient.GetFolder("Sent");
    sent.Open(FolderAccess.ReadOnly);
    var query = SearchQuery.DeliveredAfter(DateTime.Parse("2023-02-01")).And(SearchQuery.All);
    var uids = sent.Search(query);
}

The goal is to use SearchQuery in Imap mode to query the sendbox mailing list after a certain date

1

There are 1 best solutions below

2
jstedfast On

Your search query should work unless the IMAP server is broken.

FWIW, I'm not sure why you are combining your date query with ALL:

var query = SearchQuery.DeliveredAfter(DateTime.Parse("2023-02-01")).And(SearchQuery.All);

You can just use this:

var query = SearchQuery.DeliveredAfter(DateTime.Parse("2023-02-01"))

Maybe simplifying your query will be less confusing to your server?