Пример #1
0
            /// <summary>
            /// Is called when LIST command has completed.
            /// </summary>
            /// <param name="op">Asynchronous operation.</param>
            private void UidlCompleted(UidlAsyncOP op)
            {
                try{
                    // Operation failed.
                    if(op.Error != null){
                        // Assume that UIDL not supported, skip error.
                        SetState(AsyncOP_State.Completed);
                    }
                    // Operation succeeded.
                    else{
                        m_pPop3Client.m_IsUidlSupported = true;

                        // Fill messages UID info.
                        foreach(string responseLine in op.ResponseLines){
                            string[] seqNo_Uid = responseLine.Trim().Split(new char[]{' '});
                            m_pPop3Client.m_pMessages[Convert.ToInt32(seqNo_Uid[0]) - 1].SetUID(seqNo_Uid[1]);
                        }

                        SetState(AsyncOP_State.Completed);
                    }
                }                
                catch(Exception x){
                    m_pException = x;
                    m_pPop3Client.LogAddException("Exception: " + x.Message,x);
                    SetState(AsyncOP_State.Completed);
                }

                op.Dispose();
            }
Пример #2
0
        /// <summary>
        /// Starts sending UIDL command to POP3 server.
        /// </summary>
        /// <param name="op">Asynchronous operation.</param>
        /// <returns>Returns true if aynchronous operation is pending (The <see cref="UidlAsyncOP.CompletedAsync"/> event is raised upon completion of the operation).
        /// Returns false if operation completed synchronously.</returns>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when POP3 client is not in valid state. For example 'not connected'.</exception>
        /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception>
        private bool UidlAsync(UidlAsyncOP op)
        {
            if(this.IsDisposed){
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if(!this.IsConnected){
                throw new InvalidOperationException("You must connect first.");
            }
            if(op == null){
                throw new ArgumentNullException("op");
            }
            if(op.State != AsyncOP_State.WaitingForStart){
                throw new ArgumentException("Invalid argument 'op' state, 'op' must be in 'AsyncOP_State.WaitingForStart' state.","op");
            }

            return op.Start(this);
        }
Пример #3
0
            /// <summary>
            /// Is called when LIST command has completed.
            /// </summary>
            /// <param name="op">Asynchronous operation.</param>
            private void ListCompleted(ListAsyncOP op)
            {
                try{
                    // Operation failed.
                    if(op.Error != null){
                        m_pException = op.Error;
                        m_pPop3Client.LogAddException("Exception: " + op.Error.Message,op.Error);
                        SetState(AsyncOP_State.Completed);
                    }
                    // Operation succeeded.
                    else{
                        // Fill messages info.
                        m_pPop3Client.m_pMessages = new POP3_ClientMessageCollection(m_pPop3Client);
                        foreach(string seqNo_Size in op.ResponseLines){
                            m_pPop3Client.m_pMessages.Add(Convert.ToInt32(seqNo_Size.Trim().Split(new char[]{' '})[1]));
                        }

                        // Try to UID's for messages(If server supports UIDL).
                        // Start executing LIST command.
                        POP3_Client.UidlAsyncOP uidlOP = new UidlAsyncOP();
                        uidlOP.CompletedAsync += delegate(object sender,EventArgs<UidlAsyncOP> e){
                            UidlCompleted(uidlOP);
                        };
                        if(!m_pPop3Client.UidlAsync(uidlOP)){
                            UidlCompleted(uidlOP);
                        }
                    }
                }                
                catch(Exception x){
                    m_pException = x;
                    m_pPop3Client.LogAddException("Exception: " + x.Message,x);
                    SetState(AsyncOP_State.Completed);
                }

                op.Dispose();
            }