jstedfast/MailKit · error · NotSupportedException
The folder does not support partial sorts.
Error message
The folder does not support partial sorts.
What it means
The base MailFolder.Sort overload (with PartialRange) throws NotSupportedException because partial sorts are only implemented by folder types/servers that support them (IMAP SORT with range support). The base virtual body always throws after its argument validation.
Solutions
- Use non-partial Sort(options, query, orderBy) and apply Skip/Take on the returned results.
- Confirm the folder is an ImapFolder and the server advertises SORT support before using the partial overload.
- Sort client-side: fetch summaries then order them with LINQ.
Example fix
// before var results = folder.Sort(SearchOptions.None, query, orderBy, partialRange); // after var results = folder.Sort(SearchOptions.None, query, orderBy).Skip(0).Take(20).ToArray();
Defensive patterns
Strategy: try-catch
Validate before calling
if (!(folder is ImapFolder))
useClientSideSort = true; Type guard
bool supportsServerSort = folder is ImapFolder;
Try / catch
try {
results = folder.Sort(options, query, orderBy, partialRange);
} catch (NotSupportedException) {
var uids = folder.Sort(options, query, orderBy);
results = uids.Skip(skip).Take(take).ToArray();
} Prevention
- Gate partial sort behind an ImapFolder type check
- Provide a client-side sort fallback path
- Test against the actual server capabilities in integration tests
When it happens
Trigger: Calling Sort(SearchOptions, SearchQuery, IList<OrderBy>, PartialRange, CancellationToken) on a folder whose implementation is the base stub, after query/orderBy/options validation passes.
Common situations: Server-side sorted, paged listings attempted against non-IMAP folders or servers lacking the sort capability.
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 folder does not support partial searches.
- The IMAP server does not support the PARTIAL extension.
- The IMAP server does not support negative partial ranges.
- The IMAP server does not support the SORT extension.
- The IMAP server does not support the ESORT extension.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/10b8de07c0ca04ed.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/MailFolder.cs:9256
/// </exception>
/// <exception cref="CommandException">
/// The command failed.
/// </exception>
public virtual SearchResults Sort (SearchOptions options, SearchQuery query, IList<OrderBy> orderBy, PartialRange partialRange, CancellationToken cancellationToken = default)
{
if ((options & SearchOptions.All) != 0)
throw new ArgumentException ("The SearchOptions.All flag cannot be combined with a partial range.", nameof (options));
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));
throw new NotSupportedException ("The folder does not support partial sorts.");
}
/// <summary>
/// Asynchronously sort messages matching the specified query, returning only the specified range of results.
/// </summary>
/// <remarks>
/// <para>Asynchronously searches the folder for messages matching the specified query, returning only the
/// search results within the specified range in the specified sort order.</para>
/// <para>Positive positions within the <paramref name="partialRange"/> range are relative to the first result
/// in the sort order while negative positions are relative to the last result. For example, a range of
/// <c>1:50</c> will return the first 50 results in the specified sort order.</para>
/// <note type="note">If the range specified by <paramref name="partialRange"/> references results beyond the end
/// of the complete set of matching messages, then the results will only contain the unique identifiers that
/// fall within the range (if any).</note>
/// </remarks>
/// <returns>The search results.</returns>
/// <param name="options">The search options.</param>
/// <param name="query">The search query.</param>View on GitHub (pinned to 9d3859a785)