{"record":{"id":"29a01a357886da0e","repo":"jstedfast/MailKit","slug":"the-imap-server-does-not-support-the-sort-display-extension","errorCode":null,"errorMessage":"The IMAP server does not support the SORT=DISPLAY extension.","messagePattern":"The IMAP server does not support the SORT=DISPLAY extension\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolderSearch.cs","lineNumber":439,"sourceCode":"\t\t\t\t\tbuilder.Append (\"REVERSE \");\n\n\t\t\t\tswitch (orderBy[i].Type) {\n\t\t\t\tcase OrderByType.Annotation:\n\t\t\t\t\tif ((Engine.Capabilities & ImapCapabilities.Annotate) == 0)\n\t\t\t\t\t\tthrow new NotSupportedException (\"The ANNOTATION search term is not supported by the IMAP server.\");\n\n\t\t\t\t\tvar annotation = (OrderByAnnotation) orderBy[i];\n\t\t\t\t\tbuilder.Append (\"ANNOTATION \");\n\t\t\t\t\tbuilder.Append (annotation.Entry);\n\t\t\t\t\tbuilder.Append (' ');\n\t\t\t\t\tbuilder.Append (annotation.Attribute);\n\t\t\t\t\tbreak;\n\t\t\t\tcase OrderByType.Arrival:     builder.Append (\"ARRIVAL\"); break;\n\t\t\t\tcase OrderByType.Cc:          builder.Append (\"CC\"); break;\n\t\t\t\tcase OrderByType.Date:        builder.Append (\"DATE\"); break;\n\t\t\t\tcase OrderByType.DisplayFrom:\n\t\t\t\t\tif ((Engine.Capabilities & ImapCapabilities.SortDisplay) == 0)\n\t\t\t\t\t\tthrow new NotSupportedException (\"The IMAP server does not support the SORT=DISPLAY extension.\");\n\n\t\t\t\t\tbuilder.Append (\"DISPLAYFROM\");\n\t\t\t\t\tbreak;\n\t\t\t\tcase OrderByType.DisplayTo:\n\t\t\t\t\tif ((Engine.Capabilities & ImapCapabilities.SortDisplay) == 0)\n\t\t\t\t\t\tthrow new NotSupportedException (\"The IMAP server does not support the SORT=DISPLAY extension.\");\n\n\t\t\t\t\tbuilder.Append (\"DISPLAYTO\");\n\t\t\t\t\tbreak;\n\t\t\t\tcase OrderByType.From:        builder.Append (\"FROM\"); break;\n\t\t\t\tcase OrderByType.Size:        builder.Append (\"SIZE\"); break;\n\t\t\t\tcase OrderByType.Subject:     builder.Append (\"SUBJECT\"); break;\n\t\t\t\tcase OrderByType.To:          builder.Append (\"TO\"); break;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbuilder.Append (')');\n\n\t\t\treturn builder.ToString ();","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolderSearch.cs#L421-L457","documentation":"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.","triggerScenarios":"Calling ImapFolder.Sort / Search with orderBy containing `OrderBy.DisplayFrom` on a server whose Capabilities lack ImapCapabilities.SortDisplay.","commonSituations":"Sorting a mailbox by display name on servers that only implement basic SORT (many Dovecot/Cyrus configs without the display extension).","solutions":["Check `client.Capabilities.HasFlag (ImapCapabilities.SortDisplay)` before using DisplayFrom and fall back to OrderBy.From.","Fetch From headers and sort the results client-side by the display name.","Enable/configure the SORT=DISPLAY extension on the server if you control it."],"exampleFix":"// before\nvar uids = folder.Sort (new[] { OrderBy.DisplayFrom }, SearchQuery.All);\n// after\nvar sort = client.Capabilities.HasFlag (ImapCapabilities.SortDisplay)\n    ? new[] { OrderBy.DisplayFrom }\n    : new[] { OrderBy.From };\nvar uids = folder.Sort (sort, SearchQuery.All);","handlingStrategy":"validation","validationCode":"if (!client.Capabilities.HasFlag (ImapCapabilities.SortDisplay))\n    throw new InvalidOperationException (\"Server does not support SORT=DISPLAY; use OrderBy.From instead.\");","typeGuard":null,"tryCatchPattern":"try {\n    uids = folder.Sort (new[] { OrderBy.DisplayFrom }, query);\n} catch (NotSupportedException) {\n    uids = folder.Sort (new[] { OrderBy.From }, query);\n}","preventionTips":["Check ImapCapabilities.SortDisplay before using DisplayFrom/DisplayTo.","Fall back to OrderBy.From/To or sort client-side on fetched headers.","Verify sort capability support when onboarding a new IMAP provider."],"tags":["imap","sorting","capability-check","sort-display"],"backgroundTag":"unsupported-operation","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}