Example #1
0
        /// <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.WriteLine(MESSAGE_GOODBYE);
                        context.Close();
                        continue;
                    }

                    String[] inputs = inputLine.Split(" ".ToCharArray());

                    switch (inputs[0].ToLower())
                    {
                        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 ex)
                {
                    SocketException sx = ex as SocketException;

                    if (sx != null && sx.ErrorCode == 10060)
                        context.WriteLine(MESSAGE_GOODBYE);
                    //else
                    //    context.WriteLine(MESSAGE_SYSTEM_ERROR);

                    isRunning = false;
                    context.Socket.Dispose();
                }
            }
        }
Example #2
0
        /// <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.WriteLine(MESSAGE_GOODBYE);
                        context.Close();
                        continue;
                    }

                    string[] inputs = inputLine.Split(" ".ToCharArray());

                    switch (inputs[0].ToLower())
                    {
                    case "helo":
                        this.Helo(context, inputs);
                        break;

                    case "ehlo":
                        context.WriteLine("250-{inputs[1]}");
                        context.WriteLine("250 AUTH PLAIN");
                        context.LastCommand = COMMAND_HELO;
                        break;

                    case "rset":
                        this.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"))
                        {
                            this.Mail(context, inputLine.Substring(inputLine.IndexOf(" ")));
                            break;
                        }

                        context.WriteLine(MESSAGE_UNKNOWN_COMMAND);
                        break;

                    case "rcpt":
                        if (inputs[1].ToLower().StartsWith("to"))
                        {
                            this.Rcpt(context, inputLine.Substring(inputLine.IndexOf(" ")));
                            break;
                        }

                        context.WriteLine(MESSAGE_UNKNOWN_COMMAND);
                        break;

                    case "data":
                        this.Data(context);
                        break;

                    case "auth":
                        context.WriteLine("235 Authentication successful.");
                        break;

                    default:
                        context.WriteLine(MESSAGE_UNKNOWN_COMMAND);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    SocketException sx = ex as SocketException;

                    if (sx != null && sx.ErrorCode == 10060)
                    {
                        context.WriteLine(MESSAGE_GOODBYE);
                    }

                    // else
                    //    context.WriteLine(MESSAGE_SYSTEM_ERROR);

                    isRunning = false;
                    context.Socket.Dispose();
                }
            }
        }
Example #3
0
        /// <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;
                    }

                    String[] inputs = inputLine.Split(" ".ToCharArray());

                    switch (inputs[0].ToLower())
                    {
                    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
                {
                    context.WriteLine(MESSAGE_SYSTEM_ERROR);
                }
            }
        }