Beispiel #1
0
        /// <summary>
        /// Disconnect the service.
        /// </summary>
        /// <remarks>
        /// If <paramref name="quit"/> is <c>true</c>, a "LOGOUT" command will be issued in order to disconnect cleanly.
        /// </remarks>
        /// <param name="quit">If set to <c>true</c>, a "LOGOUT" command will be issued in order to disconnect cleanly.</param>
        /// <param name="cancellationToken">A cancellation token.</param>
        /// <exception cref="System.ObjectDisposedException">
        /// The <see cref="ImapClient"/> has been disposed.
        /// </exception>
        public void Disconnect(bool quit, CancellationToken cancellationToken)
        {
            CheckDisposed();

            if (!engine.IsConnected)
            {
                return;
            }

            if (quit)
            {
                try {
                    var ic = engine.QueueCommand(cancellationToken, null, "LOGOUT\r\n");

                    engine.Wait(ic);
                } catch (OperationCanceledException) {
                } catch (ImapProtocolException) {
                } catch (ImapCommandException) {
                } catch (IOException) {
                }
            }

            engine.Disconnect();

#if NETFX_CORE
            socket.Dispose();
            socket = null;
#endif
        }