/// <summary>
 /// Resets this context for a new message
 /// </summary>
 public void Reset()
 {
     this._Log.Debug("Resetting SmtpContext.");
     this.inputBuffer.Length = 0;
     this.rawSmtpMessage     = new RawSmtpMessage(this.localEndPoint.Address, this.localEndPoint.Port, this.remoteEndPoint.Address, this.remoteEndPoint.Port);
     this.lastCommand        = SmtpProcessor.COMMAND_HELO;
     this._Log.Debug("Done resetting SmtpContext.");
 }
Exemple #2
0
 /// <summary>
 /// Creates a new message.
 /// </summary>
 public SmtpMessage(RawSmtpMessage rawSmtpMessage)
 {
     this.rawSmtpMessage = rawSmtpMessage;
     using (MailMessage mailMessage = MailMessageMimeParser.ParseMessage(new System.IO.StringReader(this.rawSmtpMessage.Data.ToString())))
     {
         this.Headers         = mailMessage.Headers;
         this.FromAddress     = new EmailAddress(mailMessage.From.Address);
         this.ToAddresses     = rawSmtpMessage.Recipients.ToArray();
         this.MessageParts    = mailMessage.Parts();
         this.LocalIPAddress  = rawSmtpMessage.LocalIPAddress;
         this.LocalPort       = rawSmtpMessage.LocalPort;
         this.RemoteIPAddress = rawSmtpMessage.RemoteIPAddress;
         this.RemotePort      = rawSmtpMessage.RemotePort;
     }
 }
 /// <summary>
 /// Creates a new message.
 /// </summary>
 public SmtpMessage(RawSmtpMessage rawSmtpMessage)
 {
     this.rawSmtpMessage = rawSmtpMessage;
     using (MailMessage mailMessage = MailMessageMimeParser.ParseMessage(new System.IO.StringReader(this.rawSmtpMessage.Data.ToString())))
     {
         this.Headers = mailMessage.Headers;
         this.FromAddress = new EmailAddress(mailMessage.From.Address);
         this.ToAddresses = rawSmtpMessage.Recipients.ToArray();
         this.MessageParts = mailMessage.Parts();
         this.LocalIPAddress = rawSmtpMessage.LocalIPAddress;
         this.LocalPort = rawSmtpMessage.LocalPort;
         this.RemoteIPAddress = rawSmtpMessage.RemoteIPAddress;
         this.RemotePort = rawSmtpMessage.RemotePort;
     }
 }
        /// <summary>
        /// Initialize this context for a given socket connection.
        /// </summary>
        public SmtpContext(Socket socket)
        {
            this.lastCommand = -1;
            this.socket      = socket;

            // Set the encoding to ASCII.
            this.encoding = Encoding.ASCII;

            // Initialize the input buffer
            this.inputBuffer = new StringBuilder();

            this.remoteEndPoint = socket.RemoteEndPoint as IPEndPoint;
            this.localEndPoint  = socket.LocalEndPoint as IPEndPoint;

            this.rawSmtpMessage = new RawSmtpMessage(this.localEndPoint.Address, this.localEndPoint.Port, this.remoteEndPoint.Address, this.remoteEndPoint.Port);
        }
        /// <summary>
        /// Initialize this context for a given socket connection.
        /// </summary>
        public SmtpContext(Socket socket)
        {
            this.lastCommand = -1;
            this.socket = socket;

            // Set the encoding to ASCII.
            this.encoding = Encoding.ASCII;

            // Initialize the input buffer
            this.inputBuffer = new StringBuilder();

            this.remoteEndPoint = socket.RemoteEndPoint as IPEndPoint;
            this.localEndPoint = socket.LocalEndPoint as IPEndPoint;

            this.rawSmtpMessage = new RawSmtpMessage(this.localEndPoint.Address, this.localEndPoint.Port, this.remoteEndPoint.Address, this.remoteEndPoint.Port);
        }
        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();
        }
Exemple #7
0
        /// <summary>
        /// Creates a new message.
        /// </summary>
        public SmtpMessage(RawSmtpMessage rawSmtpMessage)
        {
            this.rawSmtpMessage = rawSmtpMessage;
            var rawMessage = this.rawSmtpMessage.Data.ToString();

            rawMessage = rawMessage.TrimEnd('\r', '\n');
            using (MailMessage mailMessage = MailMessageMimeParser.ParseMessage(rawMessage))
            {
                this.Headers         = mailMessage.Headers;
                this.FromAddress     = new EmailAddress(mailMessage.From.Address);
                this.ToAddresses     = rawSmtpMessage.Recipients.ToArray();
                this.MessageParts    = mailMessage.Parts();
                this.LocalIPAddress  = rawSmtpMessage.LocalIPAddress;
                this.LocalPort       = rawSmtpMessage.LocalPort;
                this.RemoteIPAddress = rawSmtpMessage.RemoteIPAddress;
                this.RemotePort      = rawSmtpMessage.RemotePort;
            }
        }
 /// <summary>
 /// Resets this context for a new message
 /// </summary>
 public void Reset()
 {
     this._Log.Debug("Resetting SmtpContext.");
     this.inputBuffer.Length = 0;
     this.rawSmtpMessage = new RawSmtpMessage(this.localEndPoint.Address, this.localEndPoint.Port, this.remoteEndPoint.Address, this.remoteEndPoint.Port);
     this.lastCommand = SmtpProcessor.COMMAND_HELO;
     this._Log.Debug("Done resetting SmtpContext.");
 }