public void Connect(string UserName, string Password, string Server, int Port)
        {
            this.UserName = UserName;
            this.Password = Password;
            this.Server   = Server;
            this.Port     = Port;
            string ResponseString;

            Connect(Server, Port);
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }

            WriteMessage("USER " + UserName + "\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }

            WriteMessage("PASS " + Password + "\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }
        }
        public void Disconnect()
        {
            string ResponseString;

            WriteMessage("QUIT\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }
        }
        public void Delete(Message MessageToDelete)
        {
            string ResponseString;

            WriteMessage("DELE " + MessageToDelete.MessageNumber + "\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }
        }
        public ICollection <Message> GetMessageList()
        {
            string ResponseString;

            List <Message> ReturnArray = new List <Message>();

            WriteMessage("LIST\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }
            bool Done = false;

            while (!Done)
            {
                Regex TempRegex = new Regex(Regex.Escape("+") + "OK.*\r\n");
                if (!ResponseString.EndsWith("\r\n.\r\n", StringComparison.InvariantCulture))
                {
                    while (!ResponseString.EndsWith("\r\n.\r\n", StringComparison.InvariantCulture))
                    {
                        ResponseString += GetResponse();
                    }
                }
                ResponseString = TempRegex.Replace(ResponseString, "");
                string[] Seperator = { "\r\n" };
                string[] Values    = ResponseString.Split(Seperator, StringSplitOptions.RemoveEmptyEntries);
                foreach (string Value in Values)
                {
                    string[] NewSeperator = { " " };
                    string[] Pair         = Value.Split(NewSeperator, StringSplitOptions.RemoveEmptyEntries);
                    if (Pair.Length > 1)
                    {
                        Message TempMessage = new Message();
                        TempMessage.MessageNumber = Int32.Parse(Pair[0], CultureInfo.InvariantCulture);
                        TempMessage.MessageSize   = Int32.Parse(Pair[1], CultureInfo.InvariantCulture);
                        TempMessage.Retrieved     = false;
                        ReturnArray.Add(TempMessage);
                    }
                    else
                    {
                        Done = true;
                        break;
                    }
                }
            }
            return(ReturnArray);
        }
        public Message GetMessage(Message MessageWanted)
        {
            string ResponseString;

            Message TempMessage = new Message();

            TempMessage.MessageSize   = MessageWanted.MessageSize;
            TempMessage.MessageNumber = MessageWanted.MessageNumber;

            WriteMessage("RETR " + MessageWanted.MessageNumber + "\r\n");
            ResponseString = GetResponse();
            if (!ResponseString.StartsWith("+OK", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Pop3Exception(ResponseString);
            }
            Regex TempRegex = new Regex(Regex.Escape("+") + "OK.*\r\n");

            ResponseString        = TempRegex.Replace(ResponseString, "");
            TempRegex             = new Regex("\r\n.\r\n$");
            TempMessage.Retrieved = true;
            string BodyText = "";

            while (true)
            {
                if (TempRegex.Match(ResponseString).Success || string.IsNullOrEmpty(ResponseString))
                {
                    BodyText += ResponseString;
                    BodyText  = TempRegex.Replace(BodyText, "");
                    break;
                }
                else
                {
                    BodyText += ResponseString;
                }
                ResponseString = GetResponse();
            }
            TempMessage.MessageBody = new Utilities.Web.Email.MIME.MIMEMessage(BodyText);

            return(TempMessage);
        }