/// <summary>
        /// Closes connection to POP3 server.
        /// </summary>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when POP3 client is not connected.</exception>
        public override void Disconnect()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            if (!IsConnected)
            {
                throw new InvalidOperationException("POP3 client is not connected.");
            }

            try
            {
                // Send QUIT command to server.
                WriteLine("QUIT");
            }
            catch {}

            try
            {
                base.Disconnect();
            }
            catch {}

            if (m_pMessages != null)
            {
                m_pMessages.Dispose();
                m_pMessages = null;
            }
            m_ApopHashKey = "";
            m_pExtCapabilities.Clear();
            m_IsUidlSupported = false;
        }
        /// <summary>
        /// Fills messages info.
        /// </summary>
        private void FillMessages()
        {
            m_pMessages = new POP3_ClientMessageCollection(this);

            /*
             *  First make messages info, then try to add UIDL if server supports.
             */

            /* NOTE: If reply is +OK, this is multiline respone and is terminated with '.'.
             *          Examples:
             *                  C: LIST
             *                  S: +OK 2 messages (320 octets)
             *                  S: 1 120
             *                  S: 2 200
             *                  S: .
             *                  ...
             *                  C: LIST 3
             *                  S: -ERR no such message, only 2 messages in maildrop
             */

            WriteLine("LIST");

            // Read first line of reply, check if it's ok.
            string line = ReadLine();

            if (!string.IsNullOrEmpty(line) && line.StartsWith("+OK"))
            {
                // Read lines while get only '.' on line itshelf.
                while (true)
                {
                    line = ReadLine();

                    // End of data
                    if (line.Trim() == ".")
                    {
                        break;
                    }
                    else
                    {
                        string[] no_size = line.Trim().Split(new[] { ' ' });
                        m_pMessages.Add(Convert.ToInt32(no_size[1]));
                    }
                }
            }
            else
            {
                throw new POP3_ClientException(line);
            }

            // Try to fill messages UIDs.

            /* NOTE: If reply is +OK, this is multiline respone and is terminated with '.'.
             *          Examples:
             *                  C: UIDL
             *                  S: +OK
             *                  S: 1 whqtswO00WBw418f9t5JxYwZ
             *                  S: 2 QhdPYR:00WBw1Ph7x7
             *                  S: .
             *                  ...
             *                  C: UIDL 3
             *                  S: -ERR no such message
             */

            WriteLine("UIDL");

            // Read first line of reply, check if it's ok
            line = ReadLine();
            if (line.StartsWith("+OK"))
            {
                m_IsUidlSupported = true;

                // Read lines while get only '.' on line itshelf.
                while (true)
                {
                    line = ReadLine();

                    // End of data
                    if (line.Trim() == ".")
                    {
                        break;
                    }
                    else
                    {
                        string[] no_uid = line.Trim().Split(new[] { ' ' });
                        m_pMessages[Convert.ToInt32(no_uid[0]) - 1].UIDL = no_uid[1];
                    }
                }
            }
            else
            {
                m_IsUidlSupported = false;
            }
        }
        /// <summary>
        /// Fills messages info.
        /// </summary>
        private void FillMessages()
        {
            m_pMessages = new POP3_ClientMessageCollection(this);

            /*
                First make messages info, then try to add UIDL if server supports.
            */

            /* NOTE: If reply is +OK, this is multiline respone and is terminated with '.'.
			Examples:
				C: LIST
				S: +OK 2 messages (320 octets)
				S: 1 120				
				S: 2 200
				S: .
				...
				C: LIST 3
				S: -ERR no such message, only 2 messages in maildrop
			*/

            WriteLine("LIST");

            // Read first line of reply, check if it's ok.
            string line = ReadLine();
            if (!string.IsNullOrEmpty(line) && line.StartsWith("+OK"))
            {
                // Read lines while get only '.' on line itshelf.
                while (true)
                {
                    line = ReadLine();

                    // End of data
                    if (line.Trim() == ".")
                    {
                        break;
                    }
                    else
                    {
                        string[] no_size = line.Trim().Split(new[] {' '});
                        m_pMessages.Add(Convert.ToInt32(no_size[1]));
                    }
                }
            }
            else
            {
                throw new POP3_ClientException(line);
            }

            // Try to fill messages UIDs.
            /* NOTE: If reply is +OK, this is multiline respone and is terminated with '.'.
			Examples:
				C: UIDL
				S: +OK
				S: 1 whqtswO00WBw418f9t5JxYwZ
				S: 2 QhdPYR:00WBw1Ph7x7
				S: .
				...
				C: UIDL 3
				S: -ERR no such message
			*/

            WriteLine("UIDL");

            // Read first line of reply, check if it's ok
            line = ReadLine();
            if (line.StartsWith("+OK"))
            {
                m_IsUidlSupported = true;

                // Read lines while get only '.' on line itshelf.
                while (true)
                {
                    line = ReadLine();

                    // End of data
                    if (line.Trim() == ".")
                    {
                        break;
                    }
                    else
                    {
                        string[] no_uid = line.Trim().Split(new[] {' '});
                        m_pMessages[Convert.ToInt32(no_uid[0]) - 1].UIDL = no_uid[1];
                    }
                }
            }
            else
            {
                m_IsUidlSupported = false;
            }
        }
        /// <summary>
        /// Closes connection to POP3 server.
        /// </summary>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when POP3 client is not connected.</exception>
        public override void Disconnect()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            if (!IsConnected)
            {
                throw new InvalidOperationException("POP3 client is not connected.");
            }

            try
            {
                // Send QUIT command to server.                
                WriteLine("QUIT");
            }
            catch {}

            try
            {
                base.Disconnect();
            }
            catch {}

            if (m_pMessages != null)
            {
                m_pMessages.Dispose();
                m_pMessages = null;
            }
            m_ApopHashKey = "";
            m_pExtCapabilities.Clear();
            m_IsUidlSupported = false;
        }