Example #1
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();
            }
Example #2
0
        /// <summary>
        /// Starts sending LIST command to POP3 server.
        /// </summary>
        /// <param name="op">Asynchronous operation.</param>
        /// <returns>Returns true if aynchronous operation is pending (The <see cref="ListAsyncOP.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 ListAsync(ListAsyncOP 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);
        }
Example #3
0
            /// <summary>
            /// Starts operation processing.
            /// </summary>
            /// <param name="owner">Owner POP3 client.</param>
            /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns>
            /// <exception cref="ArgumentNullException">Is raised when <b>owner</b> is null reference.</exception>
            internal bool Start(POP3_Client owner)
            {
                if(owner == null){
                    throw new ArgumentNullException("owner");
                }

                m_pPop3Client = owner;

                SetState(AsyncOP_State.Active);

                try{
                    // Start executing LIST command.
                    POP3_Client.ListAsyncOP listOP = new ListAsyncOP();
                    listOP.CompletedAsync += delegate(object sender,EventArgs<ListAsyncOP> e){
                        ListCompleted(listOP);
                    };
                    if(!m_pPop3Client.ListAsync(listOP)){
                        ListCompleted(listOP);
                    }
                }
                catch(Exception x){
                    m_pException = x;
                    m_pPop3Client.LogAddException("Exception: " + x.Message,x);
                    SetState(AsyncOP_State.Completed);
                }

                // Set flag rise CompletedAsync event flag. The event is raised when async op completes.
                // If already completed sync, that flag has no effect.
                lock(m_pLock){
                    m_RiseCompleted = true;

                    return m_State == AsyncOP_State.Active;
                }
            }