{"record":{"id":"c5326bf93a605d29","repo":"jstedfast/MailKit","slug":"the-imap-server-does-not-support-the-thread-extension","errorCode":null,"errorMessage":"The IMAP server does not support the THREAD extension.","messagePattern":"The IMAP server does not support the THREAD extension\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolderSearch.cs","lineNumber":2107,"sourceCode":"\t\t/// </exception>\n\t\t/// <exception cref=\"ImapProtocolException\">\n\t\t/// The server's response contained unexpected tokens.\n\t\t/// </exception>\n\t\t/// <exception cref=\"ImapCommandException\">\n\t\t/// The server replied with a NO or BAD response.\n\t\t/// </exception>\n\t\tpublic override Task<SearchResults> SortAsync (SearchOptions options, SearchQuery query, IList<OrderBy> orderBy, PartialRange partialRange, CancellationToken cancellationToken = default)\n\t\t{\n\t\t\tif ((options & SearchOptions.All) != 0)\n\t\t\t\tthrow new ArgumentException (\"The SearchOptions.All flag cannot be combined with a partial range.\", nameof (options));\n\n\t\t\treturn SortAsync (options, query, orderBy, partialRange, true, cancellationToken);\n\t\t}\n\n\t\tImapCommand QueueThreadCommand (ThreadingAlgorithm algorithm, SearchQuery query, CancellationToken cancellationToken, out string? charset)\n\t\t{\n\t\t\tif ((Engine.Capabilities & ImapCapabilities.Thread) == 0)\n\t\t\t\tthrow new NotSupportedException (\"The IMAP server does not support the THREAD extension.\");\n\n\t\t\tif (!Engine.ThreadingAlgorithms.Contains (algorithm))\n\t\t\t\tthrow new ArgumentOutOfRangeException (nameof (algorithm), \"The specified threading algorithm is not supported.\");\n\n\t\t\tif (query == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (query));\n\n\t\t\tCheckState (true, false);\n\n\t\t\tvar method = algorithm.ToString ().ToUpperInvariant ();\n\t\t\tvar args = new List<object> ();\n\t\t\tvar optimized = query.Optimize (new ImapSearchQueryOptimizer ());\n\t\t\tvar expr = BuildQueryExpression (optimized, args, out charset);\n\t\t\tvar command = $\"UID THREAD {method} {charset ?? \"US-ASCII\"} {expr}\\r\\n\";\n\n\t\t\tvar ic = new ImapCommand (Engine, cancellationToken, this, command, args.ToArray ());\n\t\t\tic.RegisterUntaggedHandler (\"THREAD\", ImapUtils.UntaggedThreadHandler);\n","sourceCodeStart":2089,"sourceCodeEnd":2125,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolderSearch.cs#L2089-L2125","documentation":"MailKit throws this NotSupportedException from QueueThreadCommand when a Thread/ThreadAsync call is made but the IMAP server has not advertised the THREAD capability (RFC 5251). The library refuses to issue a THREAD command the server cannot process.","triggerScenarios":"Calling ImapFolder.Thread or ThreadAsync (any overload) when ImapClient.Capabilities lacks ImapCapabilities.Thread.","commonSituations":"Building conversation views against servers without THREAD support (some Exchange configurations, lightweight IMAP servers); code that works on Gmail/Dovecot failing on other providers.","solutions":["Check (client.Capabilities & ImapCapabilities.Thread) != 0 before calling Thread/ThreadAsync","Fall back to client-side threading: fetch envelope/references and group messages yourself (e.g. with a JWZ threading algorithm)","OrderReferencesByThreading on fetched messages can help build threads locally","Use a server that advertises THREAD=REFERENCES/ORDEREDSUBJECT"],"exampleFix":"// before\nvar threads = folder.Thread (ThreadingAlgorithm.References, query);\n// after\nif ((client.Capabilities & ImapCapabilities.Thread) != 0)\n    var threads = folder.Thread (ThreadingAlgorithm.References, query);\nelse\n    // fetch matching messages and thread client-side\nvar messages = folder.Fetch (uids, MessageSummaryItems.Envelope | MessageSummaryItems.References);","handlingStrategy":"validation","validationCode":"bool canThread = (client.Capabilities & ImapCapabilities.Thread) != 0;","typeGuard":null,"tryCatchPattern":"try { threads = folder.Thread (ThreadingAlgorithm.References, query); } catch (NotSupportedException) { /* client-side fallback */ }","preventionTips":["Check capabilities after Authenticate","Maintain client-side threading fallback"],"tags":["imap","mailkit","capability-check","threading","not-supported"],"backgroundTag":"feature-not-enabled","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}