Exemplo n.º 1
0
        /// <summary>
        /// Is called when SMTP 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(ReadResponseAsyncOP op,CompleteConnectCallback connectCallback)
        {
            Exception error = null;

            try{
                // Greeting reading failed, we are done.
                if(op.Error != null){
                    error = op.Error;
                }
                // Greeting reading succeded.
                else{
                    /* RFC 5321 4.2.
                        Greeting = ( "220 " (Domain / address-literal) [ SP textstring ] CRLF ) /
                                   ( "220-" (Domain / address-literal) [ SP textstring ] CRLF
                                  *( "220-" [ textstring ] CRLF )
                                     "220" [ SP textstring ] CRLF )

                    */

                    // SMTP server accepted connection, get greeting text.
                    if(op.ReplyLines[0].ReplyCode == 220){
                        StringBuilder greetingText = new StringBuilder();
                        foreach(SMTP_t_ReplyLine line in op.ReplyLines){
                            greetingText.AppendLine(line.Text);
                        }

                        m_GreetingText = greetingText.ToString();
                        m_pEsmtpFeatures = new List<string>();
                        m_pRecipients = new List<string>();
                    }
                    // SMTP server rejected connection.
                    else{
                        error = new SMTP_ClientException(op.ReplyLines);
                    }
                }
            }
            catch(Exception x){
                error = x;
            }

            // Complete TCP_Client connect operation.
            connectCallback(error);
        }
Exemplo n.º 2
0
 /// <summary>
 /// This method is called when TCP client has sucessfully connected.
 /// </summary>
 /// <param name="callback">Callback to be called to complete connect operation.</param>
 protected override void OnConnected(CompleteConnectCallback callback)
 {            
     // Read SMTP server greeting response.
     ReadResponseAsyncOP readGreetingOP = new ReadResponseAsyncOP();
     readGreetingOP.CompletedAsync += delegate(object s,EventArgs<ReadResponseAsyncOP> e){
         ReadServerGreetingCompleted(readGreetingOP,callback);
     };
     if(!ReadResponseAsync(readGreetingOP)){
         ReadServerGreetingCompleted(readGreetingOP,callback);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// This method is called when TCP client has sucessfully connected.
 /// </summary>
 /// <param name="callback">Callback to be called to complete connect operation.</param>
 protected override void OnConnected(CompleteConnectCallback callback)
 {
     // Read POP3 server greeting response.
     SmartStream.ReadLineAsyncOP readGreetingOP = new SmartStream.ReadLineAsyncOP(new byte[8000],SizeExceededAction.JunkAndThrowException);
     readGreetingOP.Completed += delegate(object s,EventArgs<SmartStream.ReadLineAsyncOP> e){
         ReadServerGreetingCompleted(readGreetingOP,callback);
     };
     if(this.TcpStream.ReadLine(readGreetingOP,true)){
         ReadServerGreetingCompleted(readGreetingOP,callback);
     }
 }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// This method is called when TCP client has sucessfully connected.
        /// </summary>
        /// <param name="callback">Callback to be called to complete connect operation.</param>
        protected virtual void OnConnected(CompleteConnectCallback callback)
        {
            try{
                OnConnected();

                callback(null);
            }
            catch(Exception x){
                callback(x);
            }
        }