jstedfast/MailKit · error · NotSupportedException
The IMAP server does not support the SORT extension.
Error message
The IMAP server does not support the SORT extension.
What it means
MailKit throws this NotSupportedException from ImapFolder.Sort when the connected server did not advertise the SORT capability (RFC 5251). Server-side sorting is optional in IMAP; without the extension the client cannot ask the server to order results and must not send the UID SORT command.
Solutions
- Check client.Capabilities.HasFlag(ImapCapabilities.Sort) before calling Sort and branch to a fallback.
- Fetch messages with Search/Fetch and sort them client-side using MessageSummary properties (Date Sent, Subject, etc.).
- Configure or upgrade the IMAP server to one supporting RFC 5251 SORT.
- Catch NotSupportedException and fall back to client-side ordering transparently.
Example fix
// before
var sorted = folder.Sort (orderBy, query);
// after
if (client.Capabilities.HasFlag (ImapCapabilities.Sort)) {
var sorted = folder.Sort (orderBy, query);
} else {
var uids = folder.Search (query);
var summaries = folder.Fetch (uids, MessageSummaryItems.UniqueId | MessageSummaryItems.Envelope);
var sorted = summaries.OrderBy (m => m.Envelope.Date).ToList (); // client-side
} Defensive patterns
Strategy: fallback
Validate before calling
bool canSortServerSide = client.Capabilities.HasFlag (ImapCapabilities.Sort);
if (!canSortServerSide)
return SortClientSide (folder, query, orderBy); Try / catch
try {
ids = folder.Sort (orderBy, query);
} catch (NotSupportedException) {
var uids = folder.Search (query);
ids = SortSummariesClientSide (folder, uids, orderBy);
} Prevention
- Always feature-detect ImapCapabilities.Sort before using server-side sorting.
- Implement and test a client-side sort fallback for MessageSummary fields.
- Record server capabilities in diagnostics to spot degraded mode in production.
When it happens
Trigger: Calling folder.Sort(...) or SortAsync(...) — including the SearchQuery-based overloads — against a server whose CAPABILITY list lacks SORT.
Common situations: Pointing the app at a minimal/legacy IMAP server (some POP-adjacent gateways, old Exchange) that doesn't implement SORT; code developed against Dovecot then deployed to a constrained server.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- The IMAP server does not support the ESEARCH extension.
- The IMAP server does not support the PARTIAL extension.
- The IMAP server does not support the ESORT extension.
- The folder does not support partial sorts.
- The IMAP server does not support the QRESYNC extension.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/885515936da08c03.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Net/Imap/ImapFolderSearch.cs:1402
{
if ((options & SearchOptions.All) != 0)
throw new ArgumentException ("The SearchOptions.All flag cannot be combined with a partial range.", nameof (options));
return SearchAsync (options, query, partialRange, true, cancellationToken);
}
ImapCommand QueueSortCommand (string query, CancellationToken cancellationToken)
{
if (query == null)
throw new ArgumentNullException (nameof (query));
query = query.Trim ();
if (query.Length == 0)
throw new ArgumentException ("Cannot sort using an empty query.", nameof (query));
if ((Engine.Capabilities & ImapCapabilities.Sort) == 0)
throw new NotSupportedException ("The IMAP server does not support the SORT extension.");
CheckState (true, false);
var command = "UID SORT " + query + "\r\n";
var ic = new ImapCommand (Engine, cancellationToken, this, command);
if ((Engine.Capabilities & ImapCapabilities.ESort) != 0)
ic.RegisterUntaggedHandler ("ESEARCH", UntaggedESearchHandler);
ic.RegisterUntaggedHandler ("SORT", UntaggedSearchHandler);
ic.UserData = new SearchResults (UidValidity);
Engine.QueueCommand (ic);
return ic;
}
SearchResults ProcessSortResponse (ImapCommand ic)
{
ProcessResponseCodes (ic, null);View on GitHub (pinned to 9d3859a785)