MailKit.Net.Imap.ImapClient.Compress C# (CSharp) Метод

Compress() публичный Метод

Enable compression over the IMAP connection.

Enables compression over the IMAP connection.

If the IMAP server supports the ImapCapabilities.Compress extension, it is possible at any point after connecting to enable compression to reduce network bandwidth usage. Ideally, this method should be called before authenticating.

/// The has been disposed. /// /// The is not connected. /// /// Compression must be enabled before a folder has been selected. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the COMPRESS command with a NO or BAD response. /// /// An IMAP protocol error occurred. ///
public Compress ( CancellationToken cancellationToken = default(CancellationToken) ) : void
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void
		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);
		}