/// <summary> /// Constructor. /// </summary> /// <param name="context">The SMTP server session context.</param> internal SmtpStateMachine(SmtpSessionContext context) { _context = context; _context.SessionAuthenticated += OnSessionAuthenticated; _stateTable = new StateTable { new State(SmtpState.Initialized) { { NoopCommand.Command, TryMakeNoop }, { RsetCommand.Command, TryMakeRset }, { QuitCommand.Command, TryMakeQuit }, { HeloCommand.Command, TryMakeHelo, c => c.NetworkClient.Stream.IsSecure ? SmtpState.WaitingForMailSecure : SmtpState.WaitingForMail }, { EhloCommand.Command, TryMakeEhlo, c => c.NetworkClient.Stream.IsSecure ? SmtpState.WaitingForMailSecure : SmtpState.WaitingForMail }, }, new State(SmtpState.WaitingForMail) { { NoopCommand.Command, TryMakeNoop }, { RsetCommand.Command, TryMakeRset }, { QuitCommand.Command, TryMakeQuit }, { HeloCommand.Command, TryMakeHelo, SmtpState.WaitingForMail }, { EhloCommand.Command, TryMakeEhlo, SmtpState.WaitingForMail }, { MailCommand.Command, TryMakeMail, SmtpState.WithinTransaction } }, new State(SmtpState.WaitingForMailSecure) { { NoopCommand.Command, TryMakeNoop }, { RsetCommand.Command, TryMakeRset }, { QuitCommand.Command, TryMakeQuit }, { AuthCommand.Command, TryMakeAuth }, { HeloCommand.Command, TryMakeHelo, SmtpState.WaitingForMailSecure }, { EhloCommand.Command, TryMakeEhlo, SmtpState.WaitingForMailSecure }, { MailCommand.Command, TryMakeMail, SmtpState.WithinTransaction } }, new State(SmtpState.WithinTransaction) { { NoopCommand.Command, TryMakeNoop }, { RsetCommand.Command, TryMakeRset, c => c.NetworkClient.Stream.IsSecure ? SmtpState.WaitingForMailSecure : SmtpState.WaitingForMail }, { QuitCommand.Command, TryMakeQuit }, { RcptCommand.Command, TryMakeRcpt, SmtpState.CanAcceptData }, }, new State(SmtpState.CanAcceptData) { { NoopCommand.Command, TryMakeNoop }, { RsetCommand.Command, TryMakeRset, c => c.NetworkClient.Stream.IsSecure ? SmtpState.WaitingForMailSecure : SmtpState.WaitingForMail }, { QuitCommand.Command, TryMakeQuit }, { RcptCommand.Command, TryMakeRcpt }, { DataCommand.Command, TryMakeData, SmtpState.WaitingForMail }, } }; if (context.EndpointDefinition.AllowUnsecureAuthentication) { WaitingForMail.Add(AuthCommand.Command, TryMakeAuth); } if (context.EndpointDefinition.AuthenticationRequired) { WaitingForMail.Replace(MailCommand.Command, MakeResponse(SmtpResponse.AuthenticationRequired)); WaitingForMailSecure.Replace(MailCommand.Command, MakeResponse(SmtpResponse.AuthenticationRequired)); } if (context.ServerOptions.ServerCertificate != null && context.NetworkClient.Stream.IsSecure == false) { WaitingForMail.Add(StartTlsCommand.Command, TryMakeStartTls, SmtpState.WaitingForMailSecure); } _stateTable.Initialize(SmtpState.Initialized); }
/// <summary> /// Constructor. /// </summary> /// <param name="options">The options to assist when configuring the state machine.</param> /// <param name="context">The SMTP server session context.</param> internal SmtpStateMachine(ISmtpServerOptions options, SmtpSessionContext context) { _options = options; _context = context; _context.SessionAuthenticated += OnSessionAuthenticated; _stateTable = new StateTable { new State(SmtpState.Initialized) { #if DEBUG { "DBUG", TryMakeDbug }, #endif { "NOOP", TryMakeNoop }, { "RSET", TryMakeRset }, { "QUIT", TryMakeQuit }, { "HELO", TryMakeHelo, SmtpState.WaitingForMail }, { "EHLO", TryMakeEhlo, SmtpState.WaitingForMail }, }, new State(SmtpState.WaitingForMail) { #if DEBUG { "DBUG", TryMakeDbug }, #endif { "NOOP", TryMakeNoop }, { "RSET", TryMakeRset }, { "QUIT", TryMakeQuit }, { "HELO", TryMakeHelo, SmtpState.WaitingForMail }, { "EHLO", TryMakeEhlo, SmtpState.WaitingForMail }, { "MAIL", TryMakeMail, SmtpState.WithinTransaction }, { "STARTTLS", TryMakeStartTls, SmtpState.WaitingForMailSecure }, }, new State(SmtpState.WaitingForMailSecure) { #if DEBUG { "DBUG", TryMakeDbug }, #endif { "NOOP", TryMakeNoop }, { "RSET", TryMakeRset }, { "QUIT", TryMakeQuit }, { "AUTH", TryMakeAuth }, { "HELO", TryMakeHelo, SmtpState.WaitingForMailSecure }, { "EHLO", TryMakeEhlo, SmtpState.WaitingForMailSecure }, { "MAIL", TryMakeMail, SmtpState.WithinTransaction } }, new State(SmtpState.WithinTransaction) { #if DEBUG { "DBUG", TryMakeDbug }, #endif { "NOOP", TryMakeNoop }, { "RSET", TryMakeRset }, { "QUIT", TryMakeQuit }, { "RCPT", TryMakeRcpt, SmtpState.CanAcceptData }, }, new State(SmtpState.CanAcceptData) { #if DEBUG { "DBUG", TryMakeDbug }, #endif { "NOOP", TryMakeNoop }, { "RSET", TryMakeRset }, { "QUIT", TryMakeQuit }, { "RCPT", TryMakeRcpt }, { "DATA", TryMakeData, SmtpState.WaitingForMail }, } }; if (options.AllowUnsecureAuthentication) { _stateTable[SmtpState.WaitingForMail].Add("AUTH", TryMakeAuth); } _stateTable.Initialize(SmtpState.Initialized); }
/// <summary> /// Constructor. /// </summary> /// <param name="options">The options to assist when configuring the state machine.</param> /// <param name="commandFactory">The SMTP command factory.</param> public SmtpStateMachine(ISmtpServerOptions options, SmtpCommandFactory commandFactory) { _stateTable = new StateTable { new State(SmtpState.Initialized) { #if DEBUG { "DBUG", commandFactory.TryMakeDbug }, #endif { "NOOP", commandFactory.TryMakeNoop }, { "RSET", commandFactory.TryMakeRset }, { "QUIT", commandFactory.TryMakeQuit }, { "HELO", commandFactory.TryMakeHelo, SmtpState.WaitingForMail }, { "EHLO", commandFactory.TryMakeEhlo, SmtpState.WaitingForMail }, }, new State(SmtpState.WaitingForMail) { #if DEBUG { "DBUG", commandFactory.TryMakeDbug }, #endif { "NOOP", commandFactory.TryMakeNoop }, { "RSET", commandFactory.TryMakeRset }, { "QUIT", commandFactory.TryMakeQuit }, { "HELO", commandFactory.TryMakeHelo, SmtpState.WaitingForMail }, { "EHLO", commandFactory.TryMakeEhlo, SmtpState.WaitingForMail }, { "MAIL", commandFactory.TryMakeMail, SmtpState.WithinTransaction }, { "STARTTLS", commandFactory.TryMakeStartTls, SmtpState.WaitingForMailSecure }, }, new State(SmtpState.WaitingForMailSecure) { #if DEBUG { "DBUG", commandFactory.TryMakeDbug }, #endif { "NOOP", commandFactory.TryMakeNoop }, { "RSET", commandFactory.TryMakeRset }, { "QUIT", commandFactory.TryMakeQuit }, { "AUTH", commandFactory.TryMakeAuth }, { "HELO", commandFactory.TryMakeHelo, SmtpState.WaitingForMailSecure }, { "EHLO", commandFactory.TryMakeEhlo, SmtpState.WaitingForMailSecure }, { "MAIL", commandFactory.TryMakeMail, SmtpState.WithinTransaction } }, new State(SmtpState.WithinTransaction) { #if DEBUG { "DBUG", commandFactory.TryMakeDbug }, #endif { "NOOP", commandFactory.TryMakeNoop }, { "RSET", commandFactory.TryMakeRset }, { "QUIT", commandFactory.TryMakeQuit }, { "RCPT", commandFactory.TryMakeRcpt, SmtpState.CanAcceptData }, }, new State(SmtpState.CanAcceptData) { #if DEBUG { "DBUG", commandFactory.TryMakeDbug }, #endif { "NOOP", commandFactory.TryMakeNoop }, { "RSET", commandFactory.TryMakeRset }, { "QUIT", commandFactory.TryMakeQuit }, { "RCPT", commandFactory.TryMakeRcpt }, { "DATA", commandFactory.TryMakeData, SmtpState.WaitingForMail }, } }; if (options.AllowUnsecureAuthentication) { _stateTable[SmtpState.WaitingForMail].Add("AUTH", commandFactory.TryMakeAuth); } _stateTable.Initialize(SmtpState.Initialized); }
/// <summary> /// Constructor. /// </summary> /// <param name="options">The options to assist when configuring the state machine.</param> /// <param name="commandFactory">The SMTP command factory.</param> public SmtpStateMachine(ISmtpServerOptions options, SmtpCommandFactory commandFactory) { _stateTable = new StateTable { new State(SmtpState.Initialized) { #if DEBUG { "DBUG", commandFactory.TryMakeDbug }, #endif { "NOOP", commandFactory.TryMakeNoop }, { "RSET", commandFactory.TryMakeRset }, { "QUIT", commandFactory.TryMakeQuit }, { "HELO", commandFactory.TryMakeHelo, SmtpState.WaitingForMail }, { "EHLO", commandFactory.TryMakeEhlo, SmtpState.WaitingForMail }, }, new State(SmtpState.WaitingForMail) { #if DEBUG { "DBUG", commandFactory.TryMakeDbug }, #endif { "NOOP", commandFactory.TryMakeNoop }, { "RSET", commandFactory.TryMakeRset }, { "QUIT", commandFactory.TryMakeQuit }, { "HELO", commandFactory.TryMakeHelo, SmtpState.WaitingForMail }, { "EHLO", commandFactory.TryMakeEhlo, SmtpState.WaitingForMail }, { "MAIL", commandFactory.TryMakeMail, SmtpState.WithinTransaction }, { "STARTTLS", commandFactory.TryMakeStartTls, SmtpState.WaitingForMailSecure }, }, new State(SmtpState.WaitingForMailSecure) { #if DEBUG { "DBUG", commandFactory.TryMakeDbug }, #endif { "NOOP", commandFactory.TryMakeNoop }, { "RSET", commandFactory.TryMakeRset }, { "QUIT", commandFactory.TryMakeQuit }, { "AUTH", commandFactory.TryMakeAuth }, { "HELO", commandFactory.TryMakeHelo, SmtpState.WaitingForMailSecure }, { "EHLO", commandFactory.TryMakeEhlo, SmtpState.WaitingForMailSecure }, { "MAIL", commandFactory.TryMakeMail, SmtpState.WithinTransaction } }, new State(SmtpState.WithinTransaction) { #if DEBUG { "DBUG", commandFactory.TryMakeDbug }, #endif { "NOOP", commandFactory.TryMakeNoop }, { "RSET", commandFactory.TryMakeRset }, { "QUIT", commandFactory.TryMakeQuit }, { "RCPT", commandFactory.TryMakeRcpt, SmtpState.CanAcceptData }, }, new State(SmtpState.CanAcceptData) { #if DEBUG { "DBUG", commandFactory.TryMakeDbug }, #endif { "NOOP", commandFactory.TryMakeNoop }, { "RSET", commandFactory.TryMakeRset }, { "QUIT", commandFactory.TryMakeQuit }, { "RCPT", commandFactory.TryMakeRcpt }, { "DATA", commandFactory.TryMakeData, SmtpState.WaitingForMail }, } }; if (options.AllowUnsecureAuthentication) { _stateTable[SmtpState.WaitingForMail].Add("AUTH", commandFactory.TryMakeAuth); } _stateTable.Initialize(SmtpState.Initialized); }
internal SmtpStateMachine(SmtpServer server) { var commandFactory = new SmtpCommandFactory(server); _stateTable = new StateTable(commandFactory) { new State(0) { { "DBUG", new State.MakeDelegate(commandFactory.MakeDbug), null }, { "NOOP", new State.MakeDelegate(commandFactory.MakeNoop), null }, { "RSET", new State.MakeDelegate(commandFactory.MakeRset), null }, { "QUIT", new State.MakeDelegate(commandFactory.MakeQuit), null }, { "HELO", new State.MakeDelegate(commandFactory.MakeHelo), new int?(1) }, { "EHLO", new State.MakeDelegate(commandFactory.MakeEhlo), new int?(1) } }, new State(1) { { "DBUG", new State.MakeDelegate(commandFactory.MakeDbug), null }, { "NOOP", new State.MakeDelegate(commandFactory.MakeNoop), null }, { "RSET", new State.MakeDelegate(commandFactory.MakeRset), null }, { "QUIT", new State.MakeDelegate(commandFactory.MakeQuit), null }, { "HELO", new State.MakeDelegate(commandFactory.MakeHelo), new int?(1) }, { "EHLO", new State.MakeDelegate(commandFactory.MakeEhlo), new int?(1) }, { "MAIL", new State.MakeDelegate(commandFactory.MakeMail), new int?(3) }, { "STARTTLS", new State.MakeDelegate(commandFactory.MakeStartTls), new int?(2) } }, new State(2) { { "DBUG", new State.MakeDelegate(commandFactory.MakeDbug), null }, { "NOOP", new State.MakeDelegate(commandFactory.MakeNoop), null }, { "RSET", new State.MakeDelegate(commandFactory.MakeRset), null }, { "QUIT", new State.MakeDelegate(commandFactory.MakeQuit), null }, { "AUTH", new State.MakeDelegate(commandFactory.MakeAuth), null }, { "HELO", new State.MakeDelegate(commandFactory.MakeHelo), new int?(2) }, { "EHLO", new State.MakeDelegate(commandFactory.MakeEhlo), new int?(2) }, { "MAIL", new State.MakeDelegate(commandFactory.MakeMail), new int?(3) } }, new State(3) { { "DBUG", new State.MakeDelegate(commandFactory.MakeDbug), null }, { "NOOP", new State.MakeDelegate(commandFactory.MakeNoop), null }, { "RSET", new State.MakeDelegate(commandFactory.MakeRset), null }, { "QUIT", new State.MakeDelegate(commandFactory.MakeQuit), null }, { "RCPT", new State.MakeDelegate(commandFactory.MakeRcpt), new int?(4) } }, new State(4) { { "DBUG", new State.MakeDelegate(commandFactory.MakeDbug), null }, { "NOOP", new State.MakeDelegate(commandFactory.MakeNoop), null }, { "RSET", new State.MakeDelegate(commandFactory.MakeRset), null }, { "QUIT", new State.MakeDelegate(commandFactory.MakeQuit), null }, { "RCPT", new State.MakeDelegate(commandFactory.MakeRcpt), null }, { "DATA", new State.MakeDelegate(commandFactory.MakeData), new int?(1) } } }; _stateTable.Initialize(0); }