jstedfast/MailKit · error · NotSupportedException

The IMAP server does not support the COMPRESS extension.

Error message

The IMAP server does not support the COMPRESS extension.

What it means

Before sending the COMPRESS DEFLATE command, ImapClient checks the server's advertised CAPABILITIES for ImapCapabilities.Compress. If the server does not advertise COMPRESS=DEFLATE, the extension cannot be used and a NotSupportedException is thrown.

Solutions

  1. Check (client.Capabilities & ImapCapabilities.Compress) != 0 before calling Compress and skip gracefully otherwise
  2. Enable COMPRESS support on the server (e.g. Dovecot's zlib plugin) if you control it
  3. Use a catch of NotSupportedException to degrade gracefully to uncompressed operation

Example fix

// before
client.Compress(); // throws on servers without COMPRESS
// after
if ((client.Capabilities & ImapCapabilities.Compress) != 0)
	client.Compress();
Defensive patterns

Strategy: fallback

Validate before calling

bool canCompress = (client.Capabilities & ImapCapabilities.Compress) != 0;

Type guard

bool SupportsCompress(IMapClient c) => (c.Capabilities & ImapCapabilities.Compress) != 0;

Try / catch

try {
	client.Compress();
} catch (NotSupportedException) {
	// proceed uncompressed
}

Prevention

When it happens

Trigger: Calling ImapClient.Compress(cancellationToken) on a server whose CAPABILITIES response lacks COMPRESS=DEFLATE — common with hosted/cloud IMAP providers and Exchange.

Common situations: Enabling compression unconditionally for performance against a provider that doesn't support it; server config change removed the extension; testing against a local server without the deflate plugin (e.g. Dovecot without imap_zlib).

Related errors


AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15). Data as JSON: /api/errors/214f6b1e026d3abe. Report an issue: GitHub.

Appendix: source

Thrown at MailKit/Net/Imap/ImapClient.cs:292

			} else {
				valid = DefaultServerCertificateValidationCallback (host, certificate, chain, sslPolicyErrors);
			}

			if (!valid) {
				// Note: The SslHandshakeException.Create() method will nullify this once it's done using it.
				sslValidationInfo = new SslCertificateValidationInfo (host, certificate, chain, sslPolicyErrors);
			}

			return valid;
		}

		ImapCommand QueueCompressCommand (CancellationToken cancellationToken)
		{
			CheckDisposed ();
			CheckConnected ();

			if ((engine.Capabilities & ImapCapabilities.Compress) == 0)
				throw new NotSupportedException ("The IMAP server does not support the COMPRESS extension.");

			if (engine.State >= ImapEngineState.Selected)
				throw new InvalidOperationException ("Compression must be enabled before selecting a folder.");

#if MAILKIT_LITE
			throw new NotSupportedException ("MailKitLite does not support the COMPRESS extension.");
#else
			return engine.QueueCommand (cancellationToken, null, "COMPRESS DEFLATE\r\n");
#endif
		}

		void ProcessCompressResponse (ImapCommand ic)
		{
#if !MAILKIT_LITE
			if (ic.Response != ImapCommandResponse.Ok) {
				for (int i = 0; i < ic.RespCodes.Count; i++) {
					if (ic.RespCodes[i].Type == ImapResponseCodeType.CompressionActive)
						return;

View on GitHub (pinned to 9d3859a785)