jstedfast/MailKit · error · NotSupportedException
The IMAP server does not support the ESORT extension.
Error message
The IMAP server does not support the ESORT extension.
What it means
MailKit throws this NotSupportedException when you call a Sort/SortAsync overload with SearchOptions other than None while the IMAP server has not advertised the ESORT capability (RFC 5267/5256 extension enabling SEARCH return options with SORT). The library refuses client-side to send a command the server cannot honor.
Solutions
- Check ImapClient.Capabilities for ImapCapabilities.ESort before passing non-None options to Sort/SortAsync
- Pass SearchOptions.None if you do not need return options, and post-process the results client-side instead
- Use a server that supports ESORT (Dovecot, Gmail) or fall back to a plain Sort and compute min/max/count yourself
Example fix
// before
var results = folder.Sort (SearchOptions.Count, query, orderBy);
// after
if ((client.Capabilities & ImapCapabilities.ESort) != 0)
var results = folder.Sort (SearchOptions.Count, query, orderBy);
else
var results = folder.Sort (SearchOptions.None, query, orderBy); // count = results.UniqueIds.Count Defensive patterns
Strategy: validation
Validate before calling
bool canUseSortOptions = (client.Capabilities & ImapCapabilities.ESort) != 0;
Try / catch
try { results = folder.Sort (options, query, orderBy); } catch (NotSupportedException) { results = folder.Sort (SearchOptions.None, query, orderBy); } Prevention
- Inspect ImapClient.Capabilities after connect
- Cache capability profile per host
When it happens
Trigger: Calling ImapFolder.Sort or SortAsync with options != SearchOptions.None (e.g. SearchOptions.Count or SearchOptions.Min/Max) on a folder whose ImapClient.Capabilities lack ImapCapabilities.ESort.
Common situations: Connecting to older or minimal IMAP servers (or proxies) that support SORT but not ESORT; code written against Gmail/Dovecot that is deployed against Exchange or other servers without ESORT.
Related errors
- The ImapFolder does not support annotations.
- The IMAP server does not support the SORT extension.
- The IMAP server does not support the THREAD extension.
- The folder does not support partial sorts.
- The IMAP server does not support the METADATA extension.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/e38e3666ac2410ff.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Net/Imap/ImapFolderSearch.cs:1743
{
return SortAsync (query, orderBy, true, cancellationToken);
}
ImapCommand QueueSortCommand (SearchOptions options, SearchQuery query, IList<OrderBy> orderBy, PartialRange? partialRange, CancellationToken cancellationToken, out string? charset)
{
if (query == null)
throw new ArgumentNullException (nameof (query));
if (orderBy == null)
throw new ArgumentNullException (nameof (orderBy));
if (orderBy.Count == 0)
throw new ArgumentException ("No sort order provided.", nameof (orderBy));
CheckState (true, false);
if (options != SearchOptions.None && (Engine.Capabilities & ImapCapabilities.ESort) == 0)
throw new NotSupportedException ("The IMAP server does not support the ESORT extension.");
if (partialRange.HasValue) {
// Note: RFC 5267 strictly defines the PARTIAL sort return option under the "CONTEXT=SORT"
// capability. In practice, however, servers such as Dovecot share their search return option
// implementation between the SEARCH and SORT commands and advertise only "CONTEXT=SEARCH"
// and/or "PARTIAL" while accepting the PARTIAL return option for both commands.
if ((Engine.Capabilities & (ImapCapabilities.Partial | ImapCapabilities.Context)) == 0)
throw new NotSupportedException ("The IMAP server does not support the PARTIAL extension.");
// Note: Negative partial ranges were introduced in RFC 9394 and are not defined by RFC 5267.
if (partialRange.Value.First < 0 && (Engine.Capabilities & ImapCapabilities.Partial) == 0)
throw new NotSupportedException ("The IMAP server does not support negative partial ranges.");
}
var args = new List<object> ();
var optimized = query.Optimize (new ImapSearchQueryOptimizer ());
var expr = BuildQueryExpression (optimized, args, out charset);
var order = BuildSortOrder (orderBy);View on GitHub (pinned to 9d3859a785)