jstedfast/MailKit · error · InvalidOperationException
The QRESYNC extension has not been enabled.
Error message
The QRESYNC extension has not been enabled.
What it means
This InvalidOperationException is thrown by QueueOpenCommand when the server supports QRESYNC (capability advertised) but QRESYNC was not enabled on the client connection. QRESYNC must be enabled during connection via ImapClient capabilities/EnableCommand before a folder can be opened with quick-resync data.
Solutions
- Set client.EnableQResync = true (or include the QRESYNC enable flag/EnableCommand) BEFORE calling Connect so the extension is enabled during authentication.
- If using custom Capabilities, ensure ImapCapabilities.QuickResync is included when constructing ImapClient.
- Verify Supports(FolderFeature.QuickResync) on the client after connect; if false, fall back to plain Open.
- Restart the connection after enabling - the enable flag is sent at login time and cannot be applied retroactively to a live session in older servers.
Example fix
// before var client = new ImapClient(); client.Connect(host, 993, true); client.Authenticate(user, pass); folder.Open(FolderAccess.ReadWrite, highestModSeq); // throws // after var client = new ImapClient(); client.EnableQResync = true; // or client.Capabilities |= ImapCapabilities.QuickResync client.Connect(host, 993, true); client.Authenticate(user, pass); folder.Open(FolderAccess.ReadWrite, highestModSeq);
Defensive patterns
Strategy: validation
Validate before calling
var canQResync = (client.Capabilities & ImapCapabilities.QuickResync) != 0 && client.Supports(FolderFeature.QuickResync); if (!canQResync) folder.Open(FolderAccess.ReadWrite);
Try / catch
try { folder.Open(access, highestModSeq); } catch (InvalidOperationException) { EnableQResyncAndReconnect(client); folder.Open(access, highestModSeq); } Prevention
- Set EnableQResync (or include QuickResync in Capabilities) BEFORE calling Connect - it cannot be toggled on a live session afterwards.
- Create clients via a factory that always applies the QRESYNC setting.
- Assert client.Supports(FolderFeature.QuickResync) after connect in debug builds.
- Keep custom Capabilities subsets in sync with the extension flags you use.
When it happens
Trigger: Opening a folder with a highestModSeq/QRESYNC argument when Supports(FolderFeature.QuickResync) is false - i.e. ImapClient was created/connect without enabling QRESYNC (missing ImapCapabilities.QuickResync in client.Capabilities setup or EnableCommand not issued / EnableQResync option not set).
Common situations: Setting client.Capabilities to a subset that drops QuickResync before connect; forgetting ImapClient.EnableQResync = true (or equivalent EnableCommand(ImapCommand.QResync)) before connecting; using a client wrapper that strips extensions.
Related errors
- QRESYNC needs to be enabled immediately after…
- The IMAP server does not support the QRESYNC extension.
- The IMAP server does not support the QRESYNC extension.
- Value cannot be null. (Parameter 'name')
- Value cannot be null. (Parameter 'rights')
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/3ae720856fef4dc3.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Net/Imap/ImapFolder.cs:345
return Task.CompletedTask;
}
ImapCommand QueueOpenCommand (FolderAccess access, uint uidValidity, ulong highestModSeq, IList<UniqueId> uids, CancellationToken cancellationToken)
{
if (access != FolderAccess.ReadOnly && access != FolderAccess.ReadWrite)
throw new ArgumentOutOfRangeException (nameof (access));
if (uids == null)
throw new ArgumentNullException (nameof (uids));
CheckState (false, false);
if ((Engine.Capabilities & ImapCapabilities.QuickResync) == 0)
throw new NotSupportedException ("The IMAP server does not support the QRESYNC extension.");
if (!Supports (FolderFeature.QuickResync))
throw new InvalidOperationException ("The QRESYNC extension has not been enabled.");
string qresync;
if ((Engine.Capabilities & ImapCapabilities.Annotate) != 0 && Engine.QuirksMode != ImapQuirksMode.iCloud)
qresync = string.Format (CultureInfo.InvariantCulture, "(ANNOTATE QRESYNC ({0} {1}", uidValidity, highestModSeq);
else
qresync = string.Format (CultureInfo.InvariantCulture, "(QRESYNC ({0} {1}", uidValidity, highestModSeq);
if (uids.Count > 0) {
var set = UniqueIdSet.ToString (uids);
qresync += " " + set;
}
qresync += "))";
var command = string.Format ("{0} %F {1}\r\n", SelectOrExamine (access), qresync);
var ic = new ImapCommand (Engine, cancellationToken, this, command, this);
ic.RegisterUntaggedHandler ("FETCH", UntaggedQResyncFetchHandler);View on GitHub (pinned to 9d3859a785)