Exemple #1
0
        public Pop3Message(long position, long size, Socket client)
        {
            m_inboxPosition = position;
            m_client        = client;
            m_messageSize   = size;

            m_pop3State            = new Pop3StateObject();
            m_pop3State.workSocket = m_client;
            m_pop3State.sb         = new StringBuilder();

            //load email
            LoadEmail();

            //get body if it exists
            IEnumerator multipartEnumerator = MultipartEnumerator;

            while (multipartEnumerator.MoveNext())
            {
                Pop3Component multipart = (Pop3Component)multipartEnumerator.Current;

                if (multipart.isBody)
                {
                    m_body = multipart.Data;
                    break;
                }
            }
        }
Exemple #2
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                //retrieve the state of the object and the client socket from the async state object
                Pop3StateObject stateobj = (Pop3StateObject)ar.AsyncState;

                Socket client = stateobj.workSocket;

                //read data from the remote server
                int bytesread = client.EndReceive(ar);

                if (bytesread > 0)
                {
                    //there might be more data so store the data received so far
                    stateobj.sb.Append(Encoding.ASCII.GetString(stateobj.buffer, 0, bytesread));

                    //read more data from pop3 server ...
                    StartReceiveAgain(stateobj.sb.ToString());
                }
            }
            catch (Exception e)
            {
                m_manualEvent.Set();

                throw new Pop3ReceiveException("ReceivedCallBack Error" + e.ToString());
            }
        }
Exemple #3
0
        public Pop3Message(long position, long size, Socket client)
        {
            m_inboxPosition = position;
            m_messageSize = size;
            m_client = client;

            m_pop3State = new Pop3StateObject();
            m_pop3State.workSocket = m_client;
            m_pop3State.sb = new StringBuilder();

            // load email ...
            LoadEmail();

            // get body (if it exists) ...
            IEnumerator multipartEnumerator =
                MultipartEnumerator;

            while( multipartEnumerator.MoveNext() )
            {
                Pop3Component multipart = (Pop3Component)
                    multipartEnumerator.Current;

                if( multipart.IsBody )
                {
                    m_body = multipart.Data;
                    break;
                }
            }
        }
Exemple #4
0
        public Pop3Message()
        {
            m_inboxPosition = 0;
            m_client        = null;
            m_messageSize   = 0;

            m_pop3State            = new Pop3StateObject();
            m_pop3State.workSocket = m_client;
            m_pop3State.sb         = new StringBuilder();
        }
Exemple #5
0
        private void LoadEmail()
        {
            //tell pop server we want to start reading email (m_inboxpostion) from inbox

            Send("retr " + m_inboxPosition);

            //start receiving mail
            StartReceive();

            ParseEmail(m_pop3State.sb.ToString().Split(new char[] { '\r' }));

            //remove reading pop3state
            m_pop3State = null;
        }
Exemple #6
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                // Retrieve the state object and the client socket
                // from the asynchronous state object.

                Pop3StateObject stateObj =
                    (Pop3StateObject)ar.AsyncState;

                Socket client = stateObj.workSocket;

                // Read data from the remote device.
                int bytesRead = client.EndReceive(ar);

                if (bytesRead > 0)
                {
                    // There might be more data,
                    // so store the data received so far.

                    stateObj.sb.Append(
                        Encoding.GetEncoding(1251).GetString(stateObj.buffer
                                                             , 0, bytesRead));

                    // read more data from pop3 server ...
                    StartReceiveAgain(stateObj.sb.ToString());
                }
            }
            catch (Exception e)
            {
                m_manualEvent.Set();

                throw new
                      Pop3ReceiveException("RecieveCallback error" +
                                           e.ToString());
            }
        }
Exemple #7
0
        private void LoadEmail()
        {
            // tell pop3 server we want to start reading
            // email (m_inboxPosition) from inbox ...

            Send("retr " + m_inboxPosition);

            // start receiving email ...
            StartReceive();

            // parse email ...
            string content = m_pop3State.sb.ToString();

            if (content.Length > 5 && content.Substring(content.Length - 5, 5) == "\r\n.\r\n")
            {
                content = content.Substring(0, content.Length - 3);
            }

            // Unwrap header lines
            Regex re = new Regex(@"\r\n\s");

            while (re.IsMatch(content))
            {
                Match m = re.Match(content);
                if (m.Groups[0].Index >= content.IndexOf("\r\n\r\n"))
                {
                    break;
                }
                content = re.Replace(content, " ", 1);
            }

            ParseEmail(content.Split(new char[] { '\r' }));

            // remove reading pop3State ...
            m_pop3State = null;
        }
        public Pop3Message()
        {
            m_inboxPosition = 0;
            m_client = null;
            m_messageSize = 0;

            m_pop3State = new Pop3StateObject();
            m_pop3State.workSocket = m_client;
            m_pop3State.sb = new StringBuilder();
        }
        private void LoadEmail()
        {
            //tell pop server we want to start reading email (m_inboxpostion) from inbox

            Send("retr " + m_inboxPosition);

            //start receiving mail
            StartReceive();

            ParseEmail(m_pop3State.sb.ToString().Split(new char[] { '\r' }));

            //remove reading pop3state
            m_pop3State = null;
        }