コード例 #1
0
        /// <summary>
        /// Handle an SMTP transaction, i.e. all activity between initial connect and QUIT command.
        /// </summary>
        /// <param name="output">output stream</param>
        /// <param name="input">input stream</param>
        /// <returns>List of received SmtpMessages</returns>
        private IList HandleSmtpTransaction(StreamWriter output, StreamReader input)
        {
            // Initialize the state machine
            SmtpState   smtpState   = SmtpState.CONNECT;
            SmtpRequest smtpRequest = new SmtpRequest(SmtpActionType.CONNECT, String.Empty, smtpState);

            // Execute the connection request
            SmtpResponse smtpResponse = smtpRequest.Execute();

            // Send initial response
            SendResponse(output, smtpResponse);
            smtpState = smtpResponse.NextState;

            IList       msgList = new ArrayList();
            SmtpMessage msg     = new SmtpMessage();

            while (smtpState != SmtpState.CONNECT && smtpState != SmtpState.QUIT)
            {
                string line = input.ReadLine();

                if (line == null)
                {
                    break;
                }

                // Create request from client input and current state
                SmtpRequest request = SmtpRequest.CreateRequest(line, smtpState);
                // Execute request and create response object
                SmtpResponse response = request.Execute();
                // Move to next internal state
                smtpState = response.NextState;
                // Send reponse to client
                SendResponse(output, response);

                // Store input in message
                msg.Store(response, request.Params);

                // If message reception is complete save it
                if (smtpState == SmtpState.QUIT)
                {
                    msgList.Add(msg);
                    msg = new SmtpMessage();
                }
            }

            return(msgList);
        }
コード例 #2
0
        /// <summary>
        /// Handle an SMTP transaction, i.e. all activity between initial connect and QUIT command.
        /// </summary>
        /// <param name="output">output stream</param>
        /// <param name="input">input stream</param>
        /// <returns>List of received SmtpMessages</returns>
        private IList HandleSmtpTransaction(StreamWriter output, StreamReader input)
        {
            // Initialize the state machine
            SmtpState smtpState = SmtpState.CONNECT;
            SmtpRequest smtpRequest = new SmtpRequest(SmtpActionType.CONNECT, String.Empty, smtpState);

            // Execute the connection request
            SmtpResponse smtpResponse = smtpRequest.Execute();

            // Send initial response
            SendResponse(output, smtpResponse);
            smtpState = smtpResponse.NextState;

            IList msgList = new ArrayList();
            SmtpMessage msg = new SmtpMessage();

            while (smtpState != SmtpState.CONNECT && smtpState != SmtpState.QUIT)
            {
                string line = input.ReadLine();

                if (line == null)
                {
                    break;
                }

                // Create request from client input and current state
                SmtpRequest request = SmtpRequest.CreateRequest(line, smtpState);
                // Execute request and create response object
                SmtpResponse response = request.Execute();
                // Move to next internal state
                smtpState = response.NextState;
                // Send reponse to client
                SendResponse(output, response);

                // Store input in message
                msg.Store(response, request.Params);

                // If message reception is complete save it
                if (smtpState == SmtpState.QUIT)
                {
                    msgList.Add(msg);
                    msg = new SmtpMessage();
                }
            }

            return msgList;
        }