IsCommandValid() публичный Метод

public IsCommandValid ( Pop3Command command ) : bool
command Pop3Command
Результат bool
        public void UidlBeforeLogonShouldFail()
        {
            var state = new Pop3ServerSessionState()
                {
                    IsLoggedOn = false,
                };

            Assert.IsFalse(state.IsCommandValid(Pop3Command.Uidl));
        }
        public void UidlAfterLogonShouldSucceed()
        {
            var state = new Pop3ServerSessionState()
                {
                    IsLoggedOn = true,
                };

            Assert.IsTrue(state.IsCommandValid(Pop3Command.Uidl));
        }
Пример #3
0
        public async Task HandleConnection(IConnection connection)
        {
            _connection = connection;

            try
            {
                await SendBanner();

                while (true)
                {
                    _connection.SetTimeout(_configuration.CommandTimeout);

                    var data = await ReadUntilNewLine(_connection);

                    _log.LogInfo(new LogEvent()
                    {
                        Message        = data,
                        RemoteEndpoint = _connection.RemoteEndpoint,
                        SessionId      = _connection.SessionId
                    });

                    var command = POP3.CommandParser.ParseCommand(data);

                    if (!_state.IsCommandValid(command))
                    {
                        await SendCommandResult(new Pop3CommandReply(false, "Invalid command in current state"));

                        continue;
                    }

                    switch (command)
                    {
                    case Pop3Command.Capa:
                        await HandleCapa();

                        break;

                    case Pop3Command.Help:
                        await HandleHelp();

                        break;

                    case Pop3Command.User:
                        await HandleUser(data);

                        break;

                    case Pop3Command.Pass:
                        await HandlePass(data);

                        break;

                    case Pop3Command.Stat:
                        await HandleStat();

                        break;

                    case Pop3Command.List:
                        await HandleList();

                        break;

                    case Pop3Command.Uidl:
                        await HandleUidl();

                        break;

                    case Pop3Command.Retr:
                        await HandleRetr(data);

                        break;

                    case Pop3Command.Dele:
                        await HandleDele(data);

                        break;

                    case Pop3Command.Quit:
                        await HandleQuit();

                        throw new DisconnectedException();
                    }
                }
            }
            catch (DisconnectedException)
            {
                // Connection gone.
            }
        }