Exemple #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>
        /// <param name="messageQueue">The message queue to add any messages to</param>
        /// <returns>List of received SmtpMessages</returns>
        private void HandleSmtpTransaction(StreamWriter output, TextReader 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;

            SmtpMessage msg = new SmtpMessage();

            while (smtpState != SmtpState.CONNECT)
            {
                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;
                // Store input in message
                msg.Store(response, request.Params);

                // If message reception is complete save it
                if (smtpState == SmtpState.QUIT)
                {
                    // Remove the last carriage return and new line
                    string  mimeMessage  = msg.RawMessage;
                    byte[]  messageBytes = Encoding.ASCII.GetBytes(mimeMessage);
                    Message message      = new Message(messageBytes, true);

                    _receivedMail.Enqueue(message.ToMailMessage());

                    msg = new SmtpMessage();
                }

                // Send reponse to client after we have stored the email, so when asking for the recived mail list it will be there
                // (this was not the way it was done before)
                SendResponse(output, response);
            }
        }
	    /// <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>
	    /// <param name="messageQueue">The message queue to add any messages to</param>
	    /// <returns>List of received SmtpMessages</returns>
        private void HandleSmtpTransaction(StreamWriter output, TextReader 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;

			SmtpMessage msg = new SmtpMessage();
            
			while (smtpState != SmtpState.CONNECT)
			{
				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;
				// Store input in message
				msg.Store(response, request.Params);

				// If message reception is complete save it
				if (smtpState == SmtpState.QUIT)
				{
                    // Remove the last carriage return and new line
                    string mimeMessage = msg.RawMessage;
                    byte[] messageBytes = Encoding.ASCII.GetBytes(mimeMessage);
                    Message message = new Message(messageBytes, true);

                    _receivedMail.Enqueue(message.ToMailMessage());

					msg = new SmtpMessage();
                }

                // Send reponse to client after we have stored the email, so when asking for the recived mail list it will be there 
                // (this was not the way it was done before)
                SendResponse(output, response);

			}
		}