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

  1. Set client.EnableQResync = true (or include the QRESYNC enable flag/EnableCommand) BEFORE calling Connect so the extension is enabled during authentication.
  2. If using custom Capabilities, ensure ImapCapabilities.QuickResync is included when constructing ImapClient.
  3. Verify Supports(FolderFeature.QuickResync) on the client after connect; if false, fall back to plain Open.
  4. 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

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


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)