{"record":{"id":"f24941f99a4bc1c6","repo":"jstedfast/MailKit","slug":"the-younger-search-term-is-not-supported-by-the-imap-server","errorCode":null,"errorMessage":"The YOUNGER search term is not supported by the IMAP server.","messagePattern":"The YOUNGER search term is not supported by the IMAP server\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolderSearch.cs","lineNumber":359,"sourceCode":"\t\t\t\tbreak;\n\t\t\tcase SearchTerm.SubjectContains:\n\t\t\t\ttext = (TextSearchQuery) query;\n\t\t\t\tbuilder.Append (\"SUBJECT \");\n\t\t\t\tAddTextArgument (builder, args, text.Text, ref charset);\n\t\t\t\tbreak;\n\t\t\tcase SearchTerm.ToContains:\n\t\t\t\ttext = (TextSearchQuery) query;\n\t\t\t\tbuilder.Append (\"TO \");\n\t\t\t\tAddTextArgument (builder, args, text.Text, ref charset);\n\t\t\t\tbreak;\n\t\t\tcase SearchTerm.Uid:\n\t\t\t\tuid = (UidSearchQuery) query;\n\t\t\t\tbuilder.Append (\"UID \");\n\t\t\t\tbuilder.Append (UniqueIdSet.ToString (uid.Uids));\n\t\t\t\tbreak;\n\t\t\tcase SearchTerm.Younger:\n\t\t\t\tif ((Engine.Capabilities & ImapCapabilities.Within) == 0)\n\t\t\t\t\tthrow new NotSupportedException (\"The YOUNGER search term is not supported by the IMAP server.\");\n\n\t\t\t\tnumeric = (NumericSearchQuery) query;\n\t\t\t\tbuilder.Append (\"YOUNGER \");\n\t\t\t\tbuilder.Append (numeric.Value.ToString (CultureInfo.InvariantCulture));\n\t\t\t\tbreak;\n\t\t\tcase SearchTerm.GMailMessageId:\n\t\t\t\tif ((Engine.Capabilities & ImapCapabilities.GMailExt1) == 0)\n\t\t\t\t\tthrow new NotSupportedException (\"The X-GM-MSGID search term is not supported by the IMAP server.\");\n\n\t\t\t\tnumeric = (NumericSearchQuery) query;\n\t\t\t\tbuilder.Append (\"X-GM-MSGID \");\n\t\t\t\tbuilder.Append (numeric.Value.ToString (CultureInfo.InvariantCulture));\n\t\t\t\tbreak;\n\t\t\tcase SearchTerm.GMailThreadId:\n\t\t\t\tif ((Engine.Capabilities & ImapCapabilities.GMailExt1) == 0)\n\t\t\t\t\tthrow new NotSupportedException (\"The X-GM-THRID search term is not supported by the IMAP server.\");\n\n\t\t\t\tnumeric = (NumericSearchQuery) query;","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolderSearch.cs#L341-L377","documentation":"BuildQuery throws this NotSupportedException when a SearchQuery.Younger(seconds) term is used but the server lacks the WITHIN capability (RFC 5032). YOUNGER matches messages whose internal date is within N seconds of now. MailKit validates ImapCapabilities.Within during query serialization and throws client-side, avoiding a server BAD response.","triggerScenarios":"Calling folder.Search(SearchQuery.Younger(600)) or any NumericSearchQuery with SearchTerm.Younger on a server without ImapCapabilities.Within.","commonSituations":"'New mail in the last N minutes' pollers written against WITHIN-capable servers (Dovecot) run against Gmail/Exchange; Gmail actually advertises WITHIN but many corporate gateways do not.","solutions":["Check (client.Capabilities & ImapCapabilities.Within) != 0 before using SearchQuery.Younger.","Replace Younger(n) with SearchQuery.DeliveredSince(DateTime.Now - TimeSpan.FromSeconds(n)).","For polling scenarios, prefer tracking the highest UID and searching UidSearch(new UidRange(lastSeen + 1, UInt32.MaxValue)) instead of time-based queries."],"exampleFix":"// before\nvar uids = folder.Search(SearchQuery.Younger(600));\n\n// after\nvar since = DateTimeOffset.Now - TimeSpan.FromMinutes(10);\nvar uids = (client.Capabilities & ImapCapabilities.Within) != 0\n    ? folder.Search(SearchQuery.Younger(600))\n    : folder.Search(SearchQuery.DeliveredSince(since));","handlingStrategy":"fallback","validationCode":"var q = (client.Capabilities & ImapCapabilities.Within) != 0\n    ? SearchQuery.Younger(seconds)\n    : SearchQuery.DeliveredSince(DateTimeOffset.Now - TimeSpan.FromSeconds(seconds));","typeGuard":"bool SupportsWithin(ImapClient c) => (c.Capabilities & ImapCapabilities.Within) != 0;","tryCatchPattern":"try {\n    return folder.Search(SearchQuery.Younger(n));\n} catch (NotSupportedException) {\n    return folder.Search(SearchQuery.DeliveredSince(Now - TimeSpan.FromSeconds(n)));\n}","preventionTips":["Check ImapCapabilities.Within before Younger/Older terms.","Prefer UID-watermark polling over time-based 'recent' searches for new-mail detection.","Centralize capability checks so all gated terms go through one helper."],"tags":["imap","search","capability-check","within"],"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-15T23:17:13.987Z"}