jstedfast/MailKit · error · NotSupportedException
The SAVEDBEFORE search term is not supported by the IMAP…
Error message
The SAVEDBEFORE search term is not supported by the IMAP server.
What it means
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.
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.
Example fix
// before
var uids = folder.Search(SearchQuery.SavedBefore(DateTime.Now.AddDays(-30)));
// after
var cutoff = DateTime.Now.AddDays(-30);
var uids = (client.Capabilities & ImapCapabilities.SaveDate) != 0
? folder.Search(SearchQuery.SavedBefore(cutoff))
: folder.Search(SearchQuery.DeliveredBefore(cutoff)); Defensive patterns
Strategy: fallback
Validate before calling
var q = (client.Capabilities & ImapCapabilities.SaveDate) != 0
? SearchQuery.SavedBefore(date)
: SearchQuery.DeliveredBefore(date); Type guard
bool SupportsSaveDate(ImapClient c) => (c.Capabilities & ImapCapabilities.SaveDate) != 0;
Try / catch
try {
return folder.Search(SearchQuery.SavedBefore(date));
} catch (NotSupportedException) {
return folder.Search(SearchQuery.DeliveredBefore(date));
} Prevention
- 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.
When it happens
Trigger: Calling folder.Search(SearchQuery.SavedBefore(someDate)) or including a DateSearchQuery with SearchTerm.SavedBefore on a server without ImapCapabilities.SaveDate.
Common situations: Message-age cleanup jobs written against SAVEDATE-capable servers then run against Gmail/Exchange or older Dovecot; MailKit version upgrade introduced SaveDate terms.
Related errors
- The SAVEDATESUPPORTED search term is not supported by the…
- The SAVEDON search term is not supported by the IMAP server.
- The SAVEDSINCE search term is not supported by the IMAP…
- The ANNOTATION search term is not supported by the IMAP…
- The FILTER search term is not supported by the IMAP server.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/3a9d407dabe7872e.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Net/Imap/ImapFolderSearch.cs:297
case SearchTerm.Or:
builder.Append ("OR ");
binary = (BinarySearchQuery) query;
BuildQuery (builder, binary.Left, args, true, ref charset);
builder.Append (' ');
BuildQuery (builder, binary.Right, args, true, ref charset);
break;
case SearchTerm.Recent:
builder.Append ("RECENT");
break;
case SearchTerm.SaveDateSupported:
if ((Engine.Capabilities & ImapCapabilities.SaveDate) == 0)
throw new NotSupportedException ("The SAVEDATESUPPORTED search term is not supported by the IMAP server.");
builder.Append ("SAVEDATESUPPORTED");
break;
case SearchTerm.SavedBefore:
if ((Engine.Capabilities & ImapCapabilities.SaveDate) == 0)
throw new NotSupportedException ("The SAVEDBEFORE search term is not supported by the IMAP server.");
date = (DateSearchQuery) query;
builder.Append ("SAVEDBEFORE ");
builder.Append (FormatDateTime (date.Date));
break;
case SearchTerm.SavedOn:
if ((Engine.Capabilities & ImapCapabilities.SaveDate) == 0)
throw new NotSupportedException ("The SAVEDON search term is not supported by the IMAP server.");
date = (DateSearchQuery) query;
builder.Append ("SAVEDON ");
builder.Append (FormatDateTime (date.Date));
break;
case SearchTerm.SavedSince:
if ((Engine.Capabilities & ImapCapabilities.SaveDate) == 0)
throw new NotSupportedException ("The SAVEDSINCE search term is not supported by the IMAP server.");
date = (DateSearchQuery) query;View on GitHub (pinned to 9d3859a785)