public void Compress (CancellationToken cancellationToken = default (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.");
int capabilitiesVersion = engine.CapabilitiesVersion;
var ic = engine.QueueCommand (cancellationToken, null, "COMPRESS DEFLATE\r\n");
engine.Wait (ic);
ProcessResponseCodes (ic);
if (ic.Response != ImapCommandResponse.Ok) {
for (int i = 0; i < ic.RespCodes.Count; i++) {
if (ic.RespCodes[i].Type == ImapResponseCodeType.CompressionActive)
return;
}
throw ImapCommandException.Create ("COMPRESS", ic);
}
engine.Stream.Stream = new CompressedStream (engine.Stream.Stream);
// Query the CAPABILITIES again if the server did not include an
// untagged CAPABILITIES response to the COMPRESS command.
if (engine.CapabilitiesVersion == capabilitiesVersion)
engine.QueryCapabilities (cancellationToken);
}