+1 vote
by (520 points)

Hello,

I'm currently searching IMAP and EWS objects to return emails arrived at a specific date.

However I now want to search for e-mails that arrived at a specific date and are not already synchronized. For that I have a list of UniqueIds that have already been sychronized.

How can I search IMAP and EWS for that? I tried using ImapSearchParameters.Not and EwsSearchParameters.Not, but to no avail. It doesn't offer an "Id" or "UniqueId" parameter.

Thanks!

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (58.9k points)
selected by
 
Best answer

Hello,

unfortunatelly neither EWS, or IMAP protocol have support for directly searching for messages according to their UniqueID/EWS ID.

So you have to search for all the messages that arrived at the specific date (or according to other criteria). This will give you a list from which you have to filter out yourself the messages that already have been processed.

Something like this:

Dictionary<string, bool> processedUIDs = new Dictionary<string, bool>();

// search for messages that arrived today
ImapMessageCollection list = imap.Search(ImapSearchParameter.Arrived(DateTime.Now));
ImapMessageCollection filtered = new ImapMessageCollection();

foreach (var messageInfo in list)
{
    if (!processedUIDs.ContainsKey(messageInfo.UniqueId))
        filtered.Add(messageInfo);
}

    // now work with the filtered collection
...