/// <summary> /// Is called when FillMessagesAsync method has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> private void FillMessagesCompleted(FillMessagesAsyncOP 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{ m_pPop3Client.m_pAuthdUserIdentity = new GenericIdentity(m_pSASL.UserName,m_pSASL.Name); SetState(AsyncOP_State.Completed); } } catch(Exception x){ m_pException = x; m_pPop3Client.LogAddException("Exception: " + x.Message,x); SetState(AsyncOP_State.Completed); } op.Dispose(); }
/// <summary> /// Starts filling mailbox messages info. /// </summary> /// <param name="op">Asynchronous operation.</param> /// <returns>Returns true if aynchronous operation is pending (The <see cref="FillMessagesAsyncOP.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 FillMessagesAsync(FillMessagesAsyncOP 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); }
/// <summary> /// Is called when POP3 server response reading has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> private void AuthReadResponseCompleted(SmartStream.ReadLineAsyncOP 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{ // Log m_pPop3Client.LogAddRead(op.BytesInBuffer,op.LineUtf8); // Authentication succeeded. if(string.Equals(op.LineUtf8.Split(new char[]{' '},2)[0],"+OK",StringComparison.InvariantCultureIgnoreCase)){ // Start filling messages info. POP3_Client.FillMessagesAsyncOP fillOP = new FillMessagesAsyncOP(); fillOP.CompletedAsync += delegate(object sender,EventArgs<FillMessagesAsyncOP> e){ FillMessagesCompleted(fillOP); }; if(!m_pPop3Client.FillMessagesAsync(fillOP)){ FillMessagesCompleted(fillOP); } } // Continue authenticating. else if(op.LineUtf8.StartsWith("+")){ // + base64Data, we need to decode it. byte[] serverResponse = Convert.FromBase64String(op.LineUtf8.Split(new char[]{' '},2)[1]); byte[] clientResponse = m_pSASL.Continue(serverResponse); // We need just send SASL returned auth-response as base64. byte[] buffer = Encoding.UTF8.GetBytes(Convert.ToBase64String(clientResponse) + "\r\n"); // Log m_pPop3Client.LogAddWrite(buffer.Length,Convert.ToBase64String(clientResponse)); // Start auth-data sending. m_pPop3Client.TcpStream.BeginWrite(buffer,0,buffer.Length,this.AuthCommandSendingCompleted,null); } // Authentication rejected. else{ m_pException = new POP3_ClientException(op.LineUtf8); SetState(AsyncOP_State.Completed); } } } catch(Exception x){ m_pException = x; m_pPop3Client.LogAddException("Exception: " + x.Message,x); SetState(AsyncOP_State.Completed); } op.Dispose(); }
/// <summary> /// Is called when POP3 server PASS response reading has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> private void PassReadResponseCompleted(SmartStream.ReadLineAsyncOP 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{ // Log m_pPop3Client.LogAddRead(op.BytesInBuffer,op.LineUtf8); // Server returned success response. if(string.Equals(op.LineUtf8.Split(new char[]{' '},2)[0],"+OK",StringComparison.InvariantCultureIgnoreCase)){ // Start filling messages info. POP3_Client.FillMessagesAsyncOP fillOP = new FillMessagesAsyncOP(); fillOP.CompletedAsync += delegate(object sender,EventArgs<FillMessagesAsyncOP> e){ FillMessagesCompleted(fillOP); }; if(!m_pPop3Client.FillMessagesAsync(fillOP)){ FillMessagesCompleted(fillOP); } } // Server returned error response. else{ m_pException = new POP3_ClientException(op.LineUtf8); SetState(AsyncOP_State.Completed); } } } catch(Exception x){ m_pException = x; m_pPop3Client.LogAddException("Exception: " + x.Message,x); SetState(AsyncOP_State.Completed); } op.Dispose(); }