private void Data(SmtpContext context) { context.WriteLine(MESSAGE_START_DATA); SmtpMessage message = context.Message; IPEndPoint clientEndPoint = (IPEndPoint)context.Socket.RemoteEndPoint; StringBuilder header = new StringBuilder(); header.Append(String.Format("Received: from ({0} [{1}])", context.ClientDomain, clientEndPoint.Address)); header.Append("\r\n"); header.Append(" " + System.DateTime.Now); header.Append("\r\n"); message.AddData(header.ToString()); header.Length = 0; String line = context.ReadLine(); while (!line.Equals(".")) { message.AddData(line); message.AddData("\r\n"); line = context.ReadLine(); } // Spool the message lock (messageSpool) messageSpool.Add(message); context.WriteLine(MESSAGE_OK); // Reset the connection. context.Reset(); }
/// <summary> /// Resets this context for a new message /// </summary> public void Reset() { _Log.Debug("Resetting SmtpContext."); inputBuffer.Length = 0; message = new SmtpMessage(); lastCommand = SmtpProcessor.COMMAND_HELO; _Log.Debug("Done resetting SmtpContext."); }
/// <summary> /// Initialize this context for a given socket connection. /// </summary> public SmtpContext(Socket socket) { this.lastCommand = -1; this.socket = socket; message = new SmtpMessage(); // Set the encoding to ASCII. encoding = Encoding.ASCII; // Initialize the input buffer inputBuffer = new StringBuilder(); }
private void Data(SmtpContext context) { context.WriteLine(MESSAGE_START_DATA); RawSmtpMessage rawSmtpMessage = context.Message; IPEndPoint clientEndPoint = (IPEndPoint)context.Socket.RemoteEndPoint; StringBuilder header = new StringBuilder(); header.Append(string.Format("Received: from ({0} [{1}])", context.ClientDomain, clientEndPoint.Address)); header.Append("\r\n"); header.Append(" " + System.DateTime.Now); header.Append("\r\n"); rawSmtpMessage.Data.Append(header.ToString()); header.Length = 0; string line = context.ReadLine(); while (!line.Equals(".")) { rawSmtpMessage.Data.Append(line); rawSmtpMessage.Data.Append("\r\n"); line = context.ReadLine(); } // Spool the message lock (this.smtpMessageStore) { SmtpMessage smtpMessage = new SmtpMessage(rawSmtpMessage); if (this.smtpMessageStore != null) { this.smtpMessageStore.Add(smtpMessage); } if (this.MessageReceived != null) { this.MessageReceived(this, new MessageReceivedArgs(smtpMessage)); } } context.WriteLine(MESSAGE_OK); // Reset the connection. context.Reset(); }
public MessageReceivedArgs(SmtpMessage message) { Message = message; }