private void Data(SMTPContext context) { context.WriteLine(MESSAGE_START_DATA); IPEndPoint clientEndPoint = (IPEndPoint)context.Socket.RemoteEndPoint; StringBuilder data = new StringBuilder(); data.Append(String.Format("Received: from {0} ({0} [{1}])", context.ClientDomain, clientEndPoint.Address)); data.Append("\r\n"); data.Append(String.Format(" by {0} (Age of Wonders Email Wrapper)", domain)); data.Append("\r\n"); data.Append(" " + System.DateTime.Now); data.Append("\r\n"); String line = context.ReadLine(); while (!line.Equals(".")) { data.Append(line); data.Append("\r\n"); line = context.ReadLine(); } context.Message = new MailBuilder().CreateFromEml(data.ToString()); // Spool the message if (messageSpool == null) { //If no spooler set context.WriteLine(MESSAGE_OK); } else if (messageSpool.SpoolMessage(context.Message)) { context.WriteLine(MESSAGE_OK); } else { context.WriteLine(MESSAGE_SYSTEM_ERROR); } // Reset the connection. context.Reset(); }
/// <summary> /// Handles the command input from the client. This /// message returns when the client issues the quit command. /// </summary> private void ProcessCommands(SMTPContext context) { bool isRunning = true; String inputLine; // Loop until the client quits. while (isRunning) { try { inputLine = context.ReadLine(); if (inputLine == null) { isRunning = false; context.Close(); continue; } Trace.WriteLine("ProcessCommands Read: " + inputLine); String[] inputs = inputLine.Split(" ".ToCharArray()); switch (inputs[0].ToLower()) { case "ehlo": case "helo": Helo(context, inputs); break; case "rset": Rset(context); break; case "noop": context.WriteLine(MESSAGE_OK); break; case "quit": isRunning = false; context.WriteLine(MESSAGE_GOODBYE); context.Close(); break; case "mail": if (inputs[1].ToLower().StartsWith("from")) { Mail(context, inputLine.Substring(inputLine.IndexOf(" "))); break; } context.WriteLine(MESSAGE_UNKNOWN_COMMAND); break; case "rcpt": if (inputs[1].ToLower().StartsWith("to")) { Rcpt(context, inputLine.Substring(inputLine.IndexOf(" "))); break; } context.WriteLine(MESSAGE_UNKNOWN_COMMAND); break; case "data": Data(context); break; default: context.WriteLine(MESSAGE_UNKNOWN_COMMAND); break; } } catch (Exception exception) { Trace.WriteLine(string.Format("Connection {0}: Exception occured while processing commands: {1}", context.ConnectionId, exception.Message)); context.WriteLine(MESSAGE_SYSTEM_ERROR); throw exception; } } }