jstedfast/MailKit · error · NotSupportedException

The IMAP server does not support the SORT=DISPLAY extension.

Error message

The IMAP server does not support the SORT=DISPLAY extension.

What it means

MailKit throws this NotSupportedException in ImapFolderSearch.BuildSortOrder when the sort criteria include OrderByType.DisplayFrom but the server has not advertised the SORT=DISPLAY extension (ImapCapabilities.SortDisplay). DISPLAYFROM sorts by the RFC 5957 display address, which only servers with SORT=DISPLAY support.

Solutions

  1. Check `client.Capabilities.HasFlag (ImapCapabilities.SortDisplay)` before using DisplayFrom and fall back to OrderBy.From.
  2. Fetch From headers and sort the results client-side by the display name.
  3. Enable/configure the SORT=DISPLAY extension on the server if you control it.

Example fix

// before
var uids = folder.Sort (new[] { OrderBy.DisplayFrom }, SearchQuery.All);
// after
var sort = client.Capabilities.HasFlag (ImapCapabilities.SortDisplay)
    ? new[] { OrderBy.DisplayFrom }
    : new[] { OrderBy.From };
var uids = folder.Sort (sort, SearchQuery.All);
Defensive patterns

Strategy: validation

Validate before calling

if (!client.Capabilities.HasFlag (ImapCapabilities.SortDisplay))
    throw new InvalidOperationException ("Server does not support SORT=DISPLAY; use OrderBy.From instead.");

Try / catch

try {
    uids = folder.Sort (new[] { OrderBy.DisplayFrom }, query);
} catch (NotSupportedException) {
    uids = folder.Sort (new[] { OrderBy.From }, query);
}

Prevention

When it happens

Trigger: Calling ImapFolder.Sort / Search with orderBy containing `OrderBy.DisplayFrom` on a server whose Capabilities lack ImapCapabilities.SortDisplay.

Common situations: Sorting a mailbox by display name on servers that only implement basic SORT (many Dovecot/Cyrus configs without the display extension).

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


AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15). Data as JSON: /api/errors/29a01a357886da0e. Report an issue: GitHub.

Appendix: source

Thrown at MailKit/Net/Imap/ImapFolderSearch.cs:439

					builder.Append ("REVERSE ");

				switch (orderBy[i].Type) {
				case OrderByType.Annotation:
					if ((Engine.Capabilities & ImapCapabilities.Annotate) == 0)
						throw new NotSupportedException ("The ANNOTATION search term is not supported by the IMAP server.");

					var annotation = (OrderByAnnotation) orderBy[i];
					builder.Append ("ANNOTATION ");
					builder.Append (annotation.Entry);
					builder.Append (' ');
					builder.Append (annotation.Attribute);
					break;
				case OrderByType.Arrival:     builder.Append ("ARRIVAL"); break;
				case OrderByType.Cc:          builder.Append ("CC"); break;
				case OrderByType.Date:        builder.Append ("DATE"); break;
				case OrderByType.DisplayFrom:
					if ((Engine.Capabilities & ImapCapabilities.SortDisplay) == 0)
						throw new NotSupportedException ("The IMAP server does not support the SORT=DISPLAY extension.");

					builder.Append ("DISPLAYFROM");
					break;
				case OrderByType.DisplayTo:
					if ((Engine.Capabilities & ImapCapabilities.SortDisplay) == 0)
						throw new NotSupportedException ("The IMAP server does not support the SORT=DISPLAY extension.");

					builder.Append ("DISPLAYTO");
					break;
				case OrderByType.From:        builder.Append ("FROM"); break;
				case OrderByType.Size:        builder.Append ("SIZE"); break;
				case OrderByType.Subject:     builder.Append ("SUBJECT"); break;
				case OrderByType.To:          builder.Append ("TO"); break;
				}
			}
			builder.Append (')');

			return builder.ToString ();

View on GitHub (pinned to 9d3859a785)