示例#1
0
        protected virtual Rfc822MessageCollection _GetAllMessages()
        {
            Pop3MessageUIDInfoCollection infos;
            string str;
            Rfc822MessageCollection messages = new Rfc822MessageCollection();

            if (!this._TryGetAllUIDMessages(out infos, out str))
            {
                throw new Pop3ReceiveException(str);
            }
            for (int i = 0; i < infos.Count; i++)
            {
                PopMessage         message;
                string             str2;
                Pop3MessageUIDInfo info = infos[i];
                if (this._TryGetMessage(info.SerialNumber, info.UniqueNumber, out message, out str2))
                {
                    messages.Add(message);
                }
                else if (this.BrokenMessage == null)
                {
                    throw new Pop3ReceiveMessageException(str2, message);
                }
            }
            if (this.Completed != null)
            {
                this.Completed(this);
            }
            this.State = EPop3ClientState.Awaiting;
            return(messages);
        }
示例#2
0
        public virtual Rfc822MessageCollection GetAllMessages()
        {
            Pop3MessageUIDInfoCollection infos;
            string str;

            lock (this)
            {
                if (this.State != EPop3ClientState.Awaiting)
                {
                    throw new InvalidOperationException("Pop3Client doesn't allow executing multiple operations simulteneously in a few threads using one object");
                }
                this.State = EPop3ClientState.Busy;
            }
            if (this.ConnectionState != EPop3ConnectionState.Authenticated)
            {
                this.State = EPop3ClientState.Awaiting;
                throw new Pop3WrongStateException("The command cannot be executed in this state");
            }
            Rfc822MessageCollection messages = new Rfc822MessageCollection();

            if (this._TryGetAllUIDMessages(out infos, out str))
            {
                for (int i = infos.Count - 1; i > 0; i--)
                {
                    PopMessage         message;
                    string             str2;
                    Pop3MessageUIDInfo info = infos[i];
                    if (this._TryGetMessage(info.SerialNumber, info.UniqueNumber, out message, out str2))
                    {
                        messages.Add(message);
                    }
                    else if (this.BrokenMessage == null)
                    {
                        this.State = EPop3ClientState.Awaiting;
                        throw new Pop3ReceiveMessageException(str2, message);
                    }
                }
            }
            else
            {
                this.State = EPop3ClientState.Awaiting;
                throw new Pop3ReceiveException(str);
            }
            if (this.Completed != null)
            {
                this.Completed(this);
            }
            this.State = EPop3ClientState.Awaiting;
            return(messages);
        }
示例#3
0
        protected virtual bool _TryGetUIDMessage(uint serialNumber, out Pop3MessageUIDInfo messageUIDInfo, out string errorMessage)
        {
            UIDL         command  = new UIDL(serialNumber);
            Pop3Response response = this.DoCommand(command);

            errorMessage = "";
            if (command.Messages.Count > 0)
            {
                messageUIDInfo = command.Messages[0];
                return(true);
            }
            messageUIDInfo = null;
            errorMessage   = response.Message;
            return(false);
        }
示例#4
0
        public virtual bool TryGetUIDMessage(uint serialNumber, out Pop3MessageUIDInfo messageUIDInfo, out string errorMessage)
        {
            lock (this)
            {
                if (this.State != EPop3ClientState.Awaiting)
                {
                    messageUIDInfo = null;
                    errorMessage   = "Pop3Client doesn't allow executing multiple operations simulteneously in a few threads using one object";
                    return(false);
                }
                this.State = EPop3ClientState.Busy;
            }
            if (this.ConnectionState != EPop3ConnectionState.Authenticated)
            {
                messageUIDInfo = null;
                errorMessage   = "The command cannot be executed in this state";
                this.State     = EPop3ClientState.Awaiting;
                return(false);
            }
            bool flag = this._TryGetUIDMessage(serialNumber, out messageUIDInfo, out errorMessage);

            this.State = EPop3ClientState.Awaiting;
            return(flag);
        }