/// <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 DELE response reading has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> private void DeleReadResponseCompleted(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)){ m_pOwner.m_IsMarkedForDeletion = true; SetState(AsyncOP_State.Completed); } // 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(); }
/// <summary> /// Is called when POP3 server greeting reading has completed. /// </summary> /// <param name="op">Asynchronous operation.</param> /// <param name="connectCallback">Callback to be called to complete connect operation.</param> private void ReadServerGreetingCompleted(SmartStream.ReadLineAsyncOP op,CompleteConnectCallback connectCallback) { Exception error = null; try{ // Greeting reading failed, we are done. if(op.Error != null){ error = op.Error; } // Greeting reading succeded. else{ string line = op.LineUtf8; // Log. LogAddRead(op.BytesInBuffer,line); // POP3 server accepted connection, get greeting text. if(op.LineUtf8.StartsWith("+OK",StringComparison.InvariantCultureIgnoreCase)){ m_GreetingText = line.Substring(3).Trim(); // Try to read APOP hash key, if supports APOP. if(line.IndexOf("<") > -1 && line.IndexOf(">") > -1){ m_ApopHashKey = line.Substring(line.IndexOf("<"),line.LastIndexOf(">") - line.IndexOf("<") + 1); } } // POP3 server rejected connection. else{ error = new POP3_ClientException(line); } } } catch(Exception x){ error = x; } // Complete TCP_Client connect operation. connectCallback(error); }