{"record":{"id":"3a9d407dabe7872e","repo":"jstedfast/MailKit","slug":"the-savedbefore-search-term-is-not-supported-by-the-imap","errorCode":null,"errorMessage":"The SAVEDBEFORE search term is not supported by the IMAP server.","messagePattern":"The SAVEDBEFORE search term is not supported by the IMAP server\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapFolderSearch.cs","lineNumber":297,"sourceCode":"\t\t\tcase SearchTerm.Or:\n\t\t\t\tbuilder.Append (\"OR \");\n\t\t\t\tbinary = (BinarySearchQuery) query;\n\t\t\t\tBuildQuery (builder, binary.Left, args, true, ref charset);\n\t\t\t\tbuilder.Append (' ');\n\t\t\t\tBuildQuery (builder, binary.Right, args, true, ref charset);\n\t\t\t\tbreak;\n\t\t\tcase SearchTerm.Recent:\n\t\t\t\tbuilder.Append (\"RECENT\");\n\t\t\t\tbreak;\n\t\t\tcase SearchTerm.SaveDateSupported:\n\t\t\t\tif ((Engine.Capabilities & ImapCapabilities.SaveDate) == 0)\n\t\t\t\t\tthrow new NotSupportedException (\"The SAVEDATESUPPORTED search term is not supported by the IMAP server.\");\n\n\t\t\t\tbuilder.Append (\"SAVEDATESUPPORTED\");\n\t\t\t\tbreak;\n\t\t\tcase SearchTerm.SavedBefore:\n\t\t\t\tif ((Engine.Capabilities & ImapCapabilities.SaveDate) == 0)\n\t\t\t\t\tthrow new NotSupportedException (\"The SAVEDBEFORE search term is not supported by the IMAP server.\");\n\n\t\t\t\tdate = (DateSearchQuery) query;\n\t\t\t\tbuilder.Append (\"SAVEDBEFORE \");\n\t\t\t\tbuilder.Append (FormatDateTime (date.Date));\n\t\t\t\tbreak;\n\t\t\tcase SearchTerm.SavedOn:\n\t\t\t\tif ((Engine.Capabilities & ImapCapabilities.SaveDate) == 0)\n\t\t\t\t\tthrow new NotSupportedException (\"The SAVEDON search term is not supported by the IMAP server.\");\n\n\t\t\t\tdate = (DateSearchQuery) query;\n\t\t\t\tbuilder.Append (\"SAVEDON \");\n\t\t\t\tbuilder.Append (FormatDateTime (date.Date));\n\t\t\t\tbreak;\n\t\t\tcase SearchTerm.SavedSince:\n\t\t\t\tif ((Engine.Capabilities & ImapCapabilities.SaveDate) == 0)\n\t\t\t\t\tthrow new NotSupportedException (\"The SAVEDSINCE search term is not supported by the IMAP server.\");\n\n\t\t\t\tdate = (DateSearchQuery) query;","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapFolderSearch.cs#L279-L315","documentation":"BuildQuery throws this NotSupportedException when a SearchQuery.SavedBefore(date) term is used but the server does not advertise the SAVEDATE capability (RFC 8514, ImapCapabilities.SaveDate). SAVEDBEFORE matches messages whose savedate precedes the given date. The check happens during client-side query serialization so the search never reaches the server.","triggerScenarios":"Calling folder.Search(SearchQuery.SavedBefore(someDate)) or including a DateSearchQuery with SearchTerm.SavedBefore on a server without ImapCapabilities.SaveDate.","commonSituations":"Message-age cleanup jobs written against SAVEDATE-capable servers then run against Gmail/Exchange or older Dovecot; MailKit version upgrade introduced SaveDate terms.","solutions":["Check (client.Capabilities & ImapCapabilities.SaveDate) != 0 before using SavedBefore/SavedOn/SavedSince.","Fall back to SearchQuery.DeliveredBefore(date) which uses INTERNALDATE, supported by all IMAP servers.","Enable/upgrade a server implementation that supports SAVEDATE if true save-date semantics matter."],"exampleFix":"// before\nvar uids = folder.Search(SearchQuery.SavedBefore(DateTime.Now.AddDays(-30)));\n\n// after\nvar cutoff = DateTime.Now.AddDays(-30);\nvar uids = (client.Capabilities & ImapCapabilities.SaveDate) != 0\n    ? folder.Search(SearchQuery.SavedBefore(cutoff))\n    : folder.Search(SearchQuery.DeliveredBefore(cutoff));","handlingStrategy":"fallback","validationCode":"var q = (client.Capabilities & ImapCapabilities.SaveDate) != 0\n    ? SearchQuery.SavedBefore(date)\n    : SearchQuery.DeliveredBefore(date);","typeGuard":"bool SupportsSaveDate(ImapClient c) => (c.Capabilities & ImapCapabilities.SaveDate) != 0;","tryCatchPattern":"try {\n    return folder.Search(SearchQuery.SavedBefore(date));\n} catch (NotSupportedException) {\n    return folder.Search(SearchQuery.DeliveredBefore(date));\n}","preventionTips":["Use INTERNALDATE-based terms (DeliveredBefore) as the default and SAVEDATE only when advertised.","Note the semantic difference: savedate ≠ internaldate; don't silently substitute where semantics matter.","Log when a fallback substitutes a different timestamp so behavior differences are traceable."],"tags":["imap","search","capability-check","savedate"],"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"}