public MailRecipientsState(String host, String mailFrom, Int32?mailSize, RcptCommand cmd, Connection connection) : base(connection)
        {
            this.host           = host;
            this.mailFrom       = mailFrom;
            this.mailSize       = mailSize;
            this.initCommand    = cmd;
            this.mailRecipients = new List <String>(1);

            this.NexCommands.Add(typeof(RcptCommand));
            this.NexCommands.Add(typeof(DataCommand));
            this.NexCommands.Add(typeof(QuitCommand));
        }
        private async Task HandleCommandAsync(RcptCommand cmd)
        {
            var checkMailParamsResult = this.CheckMailParamsPlugin != null ? await this.CheckMailParamsPlugin.CheckRcptAsync(this.mailFrom, cmd.Recipient) : null;

            if (checkMailParamsResult != null && checkMailParamsResult.IsError == true)
            {
                await base.Connection.WriteLineAsync(checkMailParamsResult.ErrorText);
            }
            else
            {
                this.mailRecipients.Add(cmd.Recipient);
                await base.Connection.WriteLineAsync("250 OK");
            }
        }
 /// <summary>
 /// Visit an RCPT command.
 /// </summary>
 /// <param name="command">The command that is being visited.</param>
 protected override void Visit(RcptCommand command)
 {
     _output.WriteLine("RCPT: Address={0}", command.Address.AsAddress());
 }
Exemple #4
0
        protected async Task <CommandBase> GetCommandAsync(String line, List <Type> possibleCommands)
        {
            if (String.IsNullOrEmpty(line))
            {
                return(null);
            }

            CommandBase cmd     = null;
            String      payload = null;

            if ((payload = this.GetPayloadByCommand(line, HeloCommand.Command)) != null)
            {
                cmd = new HeloCommand(payload);
            }
            else if ((payload = this.GetPayloadByCommand(line, EhloCommand.Command)) != null)
            {
                cmd = new EhloCommand(payload);
            }
            else if ((payload = this.GetPayloadByCommand(line, StartTlsCommand.Command)) != null)
            {
                cmd = new StartTlsCommand(payload);
            }
            else if ((payload = this.GetPayloadByCommand(line, MailCommand.Command)) != null)
            {
                cmd = new MailCommand(payload);
            }
            else if ((payload = this.GetPayloadByCommand(line, RcptCommand.Command)) != null)
            {
                cmd = new RcptCommand(payload);
            }
            else if ((payload = this.GetPayloadByCommand(line, DataCommand.Command)) != null)
            {
                cmd = new DataCommand(payload);
            }
            else if ((payload = this.GetPayloadByCommand(line, QuitCommand.Command)) != null)
            {
                cmd = new QuitCommand(payload);
            }
            else if ((payload = this.GetPayloadByCommand(line, RstCommand.Command)) != null)
            {
                cmd = new RstCommand(payload);
            }
            else if ((payload = this.GetPayloadByCommand(line, NoopCommand.Command)) != null)
            {
                cmd = new NoopCommand(payload);
            }

            if (cmd != null)
            {
                if (possibleCommands.Contains(cmd.GetType()))
                {
                    var error = cmd.ParseParameter();
                    if (error == null)
                    {
                        error = await cmd.ParseParameterAsync(this.Connection);
                    }

                    if (error != null)
                    {
                        await this.Connection.WriteLineAsync(error);

                        cmd = null;
                    }
                }
                else
                {
                    cmd = new InvalidCommand(payload);
                }
            }
            else
            {
                await this.Connection.WriteLineAsync("500 Unrecognized command");
            }

            return(cmd);
        }