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.