예제 #1
0
        public IList <MailMessage> ReadAll()
        {
            var result = new List <MailMessage>();

            logger.ConnectingToPop3Server(this.hostname);

            using (Pop3Client client = new Pop3Client())
            {
                client.Connect(hostname, port, useSsl);
                client.Authenticate(username, password);

                logger.ConnectedToPop3Server(this.hostname);

                try
                {
                    int numMessages = client.GetMessageCount();
                    logger.FoundMessages(numMessages);

                    for (int messageNo = 1; messageNo <= numMessages; messageNo++)
                    {
                        logger.ReadingMessage(messageNo);
                        var pop3mail = client.GetMessage(messageNo);
                        logger.MessageRead(pop3mail);

                        var message = MakeMessage(pop3mail);
                        SaveAttachments(pop3mail, message);

                        result.Add(message);
#if !DEBUG
                        logger.DeletingMessage(messageNo);
                        client.DeleteMessage(messageNo);
#endif
                    }//for

                    logger.DisconnectingFromPop3Server(this.hostname);
                    // also forces message deletion
                    client.Disconnect();
                    logger.DisconnectedFromPop3Server(this.hostname);
                }
                catch (Exception e)
                {
                    logger.ErrorWhileReadingFromPop3Server(this.hostname, e);
                }//try

                return(result);
            }//using
        }