// --------------------------- RunList --------------------------------
        // run the List command on the server
        public MailDropMessages RunList( )
        {
            MailDropMessages messages = new MailDropMessages( );

            string[] listLines = null;
            SockEx.SendReceive("LIST" + PopConstants.CrLf);
            while (true)
            {
                if (ResponseIsPopTerminated(SockEx.ResponseBuilder) == true)
                {
                    break;
                }
                SockEx.SleepThenReadMoreAvailableData(1000);
            }
            listLines = Stringer.Split(SockEx.ResponseMessage, NetworkConstants.CrLf);

            // parse the list line output into an arraylist of MailDropMessages.
            for (int Ix = 0; Ix < listLines.Length; ++Ix)
            {
                string line = listLines[Ix];
                if ((line[0] == '+') || (line[0] == '.'))
                {
                    continue;
                }
                messages.AddMessage(new MailDropMessage(line));
            }

            return(messages);
        }
 public string RunStat( )
 {
     SockEx.SendReceive("STAT" + PopConstants.CrLf);
     if (SockEx.ResponseMessageEndsWithCrLf( ) == false)
     {
         SockEx.SleepThenReadMoreAvailableData(1000);
     }
     return(SockEx.ResponseMessage);
 }
        // ----------------------- NextEmail ----------------------------------
        public bool NextEmail( )
        {
            string returned;

            long pos;

            if (m_directPosition == -1)
            {
                if (m_inboxPosition == 0)
                {
                    pos = 1;
                }
                else
                {
                    pos = m_inboxPosition + 1;
                }
            }
            else
            {
                pos = m_directPosition + 1;
                m_directPosition = -1;
            }

            SockEx.ExpectedResponseCodes =
                new ExpectedResponseCodes(PopConstants.Ok, PopConstants.Error);
            SockEx.SendReceive("list " + pos.ToString( ) + PopConstants.CrLf);
            if (SockEx.ExpectedResponseCode == PopConstants.Error)
            {
                return(false);
            }
            else
            {
                SockEx.ThrowIfUnexpectedResponse( );
            }

            // positive response: +ok MessagePosition MessageSize.
            returned = SockEx.ResponseMessage;

            m_inboxPosition = pos;

            // strip out CRLF ...
            string[] noCr = returned.Split(new char[] { '\r' });

            // get size ...
            string[] elements = noCr[0].Split(new char[] { ' ' });

            System.Int64 size = System.Int64.Parse(elements[2]);

            // ... else read email data
            m_pop3Message = new Pop3Message(m_inboxPosition, mSockEx);

            return(true);
        }
        public bool DeleteEmail()
        {
            bool ret = false;

            SockEx.ExpectedResponseCodes = new ExpectedResponseCodes(PopConstants.Ok);
            SockEx.SendReceive("dele " + m_inboxPosition);
            SockEx.ThrowIfUnexpectedResponse( );
            string returned = SockEx.ResponseMessage;

            if (Regex.Match(returned,
                            @"^.*\+OK.*$").Success)
            {
                ret = true;
            }

            return(ret);
        }
 public void CloseConnection()
 {
     SockEx.Send("quit");
     mSockEx       = null;
     m_pop3Message = null;
 }