Limit search results to a limit but only include items that don't have the deleted flag set

0 votes
asked Jun 7 by nicksullivan (200 points)

Is there a way to do a message search that limits the returned items to 500 items but searches for a flag being set? Basically I want to pull messages that don't have the delete flag set but not all of them at once? I plan on later going back and purging the messages. Purge takes a ton of resources and is slowing down the process significantly so I figure if I can do it afterwards.

Thanks
Nick

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Jun 7 by Lukas Matyska (37,860 points)

Paging can be done like this:

int pageSize = 500;
for (int i = 1; i <= imap.CurrentFolder.TotalMessageCount; i += pageSize)
{
    var page = new ImapMessageSet();
    page.AddRange(i, i + pageSize - 1);

    var list = imap.Search(page, ImapListFields.UniqueId, ImapSearchParameter.Not(ImapSearchParameter.Deleted));
    // do something with messages ...
}

Please note this paging limits input collection, not output collection. It means that if you have pageSize = 500, the resulting list will contain 500 or less messages.

...