A stream for communicating with a POP3 server.
A stream capable of reading data line-by-line (Pop3StreamMode.Line) or by raw byte streams (Pop3StreamMode.Data).
Наследование: Stream
Пример #1
0
        /// <summary>
        /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting.
        /// </summary>
        /// <remarks>
        /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting.
        /// </remarks>
        /// <param name="pop3">The pop3 stream.</param>
        /// <param name="cancellationToken">The cancellation token</param>
        public void Connect(Pop3Stream pop3, CancellationToken cancellationToken)
        {
            if (stream != null)
            {
                stream.Dispose();
            }

            Capabilities = Pop3Capabilities.User;
            AuthenticationMechanisms.Clear();
            State     = Pop3EngineState.Disconnected;
            ApopToken = null;
            stream    = pop3;

            // read the pop3 server greeting
            var greeting = ReadLine(cancellationToken).TrimEnd();

            int    index = greeting.IndexOf(' ');
            string token, text;

            if (index != -1)
            {
                token = greeting.Substring(0, index);

                while (index < greeting.Length && char.IsWhiteSpace(greeting[index]))
                {
                    index++;
                }

                if (index < greeting.Length)
                {
                    text = greeting.Substring(index);
                }
                else
                {
                    text = string.Empty;
                }
            }
            else
            {
                text  = string.Empty;
                token = greeting;
            }

            if (token != "+OK")
            {
                stream.Dispose();
                stream = null;

                throw new Pop3ProtocolException(string.Format("Unexpected greeting from server: {0}", greeting));
            }

            index = text.IndexOf('>');
            if (text.Length > 0 && text[0] == '<' && index != -1)
            {
                ApopToken     = text.Substring(0, index + 1);
                Capabilities |= Pop3Capabilities.Apop;
            }

            State = Pop3EngineState.Connected;
        }
Пример #2
0
        /// <summary>
        /// Disconnects the <see cref="Pop3Stream"/>.
        /// </summary>
        public void Disconnect()
        {
            State = Pop3EngineState.Connection;

            if (stream != null)
            {
                stream.Dispose();
                stream = null;
            }
        }
Пример #3
0
        /// <summary>
        /// Disconnects the <see cref="Pop3Engine"/>.
        /// </summary>
        /// <remarks>
        /// Disconnects the <see cref="Pop3Engine"/>.
        /// </remarks>
        public void Disconnect()
        {
            if (stream != null)
            {
                stream.Dispose();
                stream = null;
            }

            if (State != Pop3EngineState.Disconnected)
            {
                State = Pop3EngineState.Disconnected;
                OnDisconnected();
            }
        }
Пример #4
0
 /// <summary>
 /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting.
 /// </summary>
 /// <remarks>
 /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting.
 /// </remarks>
 /// <param name="pop3">The pop3 stream.</param>
 /// <param name="cancellationToken">The cancellation token</param>
 public Task ConnectAsync(Pop3Stream pop3, CancellationToken cancellationToken)
 {
     return(ConnectAsync(pop3, true, cancellationToken));
 }
Пример #5
0
 /// <summary>
 /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting.
 /// </summary>
 /// <remarks>
 /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting.
 /// </remarks>
 /// <param name="pop3">The pop3 stream.</param>
 /// <param name="cancellationToken">The cancellation token</param>
 public void Connect(Pop3Stream pop3, CancellationToken cancellationToken)
 {
     ConnectAsync(pop3, false, cancellationToken).GetAwaiter().GetResult();
 }
Пример #6
0
        async Task ConnectAsync(Pop3Stream pop3, bool doAsync, CancellationToken cancellationToken)
        {
            if (stream != null)
            {
                stream.Dispose();
            }

            Capabilities = Pop3Capabilities.User;
            AuthenticationMechanisms.Clear();
            State     = Pop3EngineState.Disconnected;
            ApopToken = null;
            stream    = pop3;

            // read the pop3 server greeting
            var greeting = (await ReadLineAsync(doAsync, cancellationToken).ConfigureAwait(false)).TrimEnd();

            int    index = greeting.IndexOf(' ');
            string token, text;

            if (index != -1)
            {
                token = greeting.Substring(0, index);

                while (index < greeting.Length && char.IsWhiteSpace(greeting[index]))
                {
                    index++;
                }

                if (index < greeting.Length)
                {
                    text = greeting.Substring(index);
                }
                else
                {
                    text = string.Empty;
                }
            }
            else
            {
                text  = string.Empty;
                token = greeting;
            }

            if (token != "+OK")
            {
                stream.Dispose();
                stream = null;

                throw new Pop3ProtocolException(string.Format("Unexpected greeting from server: {0}", greeting));
            }

            index = text.IndexOf('<');
            if (index != -1 && index + 1 < text.Length)
            {
                int endIndex = text.IndexOf('>', index + 1);

                if (endIndex++ != -1)
                {
                    ApopToken     = text.Substring(index, endIndex - index);
                    Capabilities |= Pop3Capabilities.Apop;
                }
            }

            State = Pop3EngineState.Connected;
        }
Пример #7
0
        /// <summary>
        /// Disconnects the <see cref="Pop3Stream"/>.
        /// </summary>
        public void Disconnect()
        {
            State = Pop3EngineState.Connection;

            if (stream != null) {
                stream.Dispose ();
                stream = null;
            }
        }
Пример #8
0
        /// <summary>
        /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting.
        /// </summary>
        /// <param name="pop3">The pop3 stream.</param>
        /// <param name="cancellationToken">A cancellation token</param>
        public void Connect(Pop3Stream pop3, CancellationToken cancellationToken)
        {
            if (stream != null)
                stream.Dispose ();

            Capabilities = Pop3Capabilities.User;
            AuthenticationMechanisms.Clear ();
            State = Pop3EngineState.Connection;
            ApopToken = null;
            stream = pop3;

            // read the pop3 server greeting
            var greeting = ReadLine (cancellationToken).TrimEnd ();

            int index = greeting.IndexOf (' ');
            string token, text;

            if (index != -1) {
                token = greeting.Substring (0, index);

                while (index < greeting.Length && char.IsWhiteSpace (greeting[index]))
                    index++;

                if (index < greeting.Length)
                    text = greeting.Substring (index);
                else
                    text = string.Empty;
            } else {
                text = string.Empty;
                token = greeting;
            }

            if (token != "+OK") {
                stream.Dispose ();
                stream = null;

                throw new Pop3ProtocolException (string.Format ("Unexpected greeting from server: {0}", greeting));
            }

            index = text.IndexOf ('>');
            if (text.Length > 0 && text[0] == '<' && index != -1) {
                ApopToken = text.Substring (1, index - 1);
                Capabilities |= Pop3Capabilities.Apop;
            }

            State = Pop3EngineState.Authentication;
        }
Пример #9
0
		/// <summary>
		/// Disconnects the <see cref="Pop3Engine"/>.
		/// </summary>
		/// <remarks>
		/// Disconnects the <see cref="Pop3Engine"/>.
		/// </remarks>
		public void Disconnect ()
		{
			Uri = null;

			if (stream != null) {
				stream.Dispose ();
				stream = null;
			}

			if (State != Pop3EngineState.Disconnected) {
				State = Pop3EngineState.Disconnected;
				OnDisconnected ();
			}
		}