jstedfast/MailKit · error · NotSupportedException
The IMAP server does not support the THREAD extension.
Error message
The IMAP server does not support the THREAD extension.
What it means
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.
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
Example fix
// before
var threads = folder.Thread (ThreadingAlgorithm.References, query);
// after
if ((client.Capabilities & ImapCapabilities.Thread) != 0)
var threads = folder.Thread (ThreadingAlgorithm.References, query);
else
// fetch matching messages and thread client-side
var messages = folder.Fetch (uids, MessageSummaryItems.Envelope | MessageSummaryItems.References); Defensive patterns
Strategy: validation
Validate before calling
bool canThread = (client.Capabilities & ImapCapabilities.Thread) != 0;
Try / catch
try { threads = folder.Thread (ThreadingAlgorithm.References, query); } catch (NotSupportedException) { /* client-side fallback */ } Prevention
- Check capabilities after Authenticate
- Maintain client-side threading fallback
When it happens
Trigger: Calling ImapFolder.Thread or ThreadAsync (any overload) when ImapClient.Capabilities lacks ImapCapabilities.Thread.
Common situations: Building conversation views against servers without THREAD support (some Exchange configurations, lightweight IMAP servers); code that works on Gmail/Dovecot failing on other providers.
Related errors
- The ImapFolder does not support annotations.
- The IMAP server does not support the ESORT extension.
- The IMAP server does not support the METADATA extension.
- The IMAP server does not support the QUOTA extension.
- The IMAP server does not support the UTF8 extension.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/c5326bf93a605d29.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Net/Imap/ImapFolderSearch.cs:2107
/// </exception>
/// <exception cref="ImapProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="ImapCommandException">
/// The server replied with a NO or BAD response.
/// </exception>
public override Task<SearchResults> SortAsync (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));
return SortAsync (options, query, orderBy, partialRange, true, cancellationToken);
}
ImapCommand QueueThreadCommand (ThreadingAlgorithm algorithm, SearchQuery query, CancellationToken cancellationToken, out string? charset)
{
if ((Engine.Capabilities & ImapCapabilities.Thread) == 0)
throw new NotSupportedException ("The IMAP server does not support the THREAD extension.");
if (!Engine.ThreadingAlgorithms.Contains (algorithm))
throw new ArgumentOutOfRangeException (nameof (algorithm), "The specified threading algorithm is not supported.");
if (query == null)
throw new ArgumentNullException (nameof (query));
CheckState (true, false);
var method = algorithm.ToString ().ToUpperInvariant ();
var args = new List<object> ();
var optimized = query.Optimize (new ImapSearchQueryOptimizer ());
var expr = BuildQueryExpression (optimized, args, out charset);
var command = $"UID THREAD {method} {charset ?? "US-ASCII"} {expr}\r\n";
var ic = new ImapCommand (Engine, cancellationToken, this, command, args.ToArray ());
ic.RegisterUntaggedHandler ("THREAD", ImapUtils.UntaggedThreadHandler);
View on GitHub (pinned to 9d3859a785)