/// <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); }
public SmtpCommandFactoryTests() { var options = new SmtpServerOptions { ServerName = "test.smtp.com" }; _smtpCommandFactory = new SmtpCommandFactory(options, new SmtpParser()); }