0 votes

If I want to search imap folder content and sort it by date descending. How can I achieve it?

by

1 Answer

0 votes
 
Best answer

If your IMAP server supports SORT extension:

List<ImapExtension> capability = client.SupportedExtensions();
bool supportsSort = capability.Contains(ImapExtension.Sort);

Use Search and Sort methods on IMAP client:

List<long> uids = client.Search()
    .Where(Expression.Subject("subject"))
    .Sort(SortBy.Multiple(
        SortBy.Reverse(SortBy.Date()), 
        SortBy.Subject()
        )
    );

Alternatively you could use the fact that uids are assigned in ascending order - you can easily search on the server and then simply sort on the client side.

by (296k points)
...