Beispiel #1
0
        public async Task CommandCompletedAsync(
            ImapMessage message,
            IImapCommand command,
            CancellationToken cancellationToken)
        {
            await SendPendingResponsesAsync(cancellationToken);

            await this.SendMessageAsync(message, cancellationToken);
            await EndCommandWithoutResponseAsync(command, cancellationToken);
        }
Beispiel #2
0
        public async Task EndCommandWithoutResponseAsync(IImapCommand command, CancellationToken cancellationToken)
        {
            _outstandingCommands.Remove(command);

            while (_pendingCommands.Count > 0 && CanRunImmediately(_pendingCommands.Peek()))
            {
                IImapCommand newCommand = _pendingCommands.Dequeue();
                _outstandingCommands.Add(newCommand);
                await newCommand.ExecuteAsync(cancellationToken);
            }
        }
Beispiel #3
0
        private bool CanRunImmediately(IImapCommand command)
        {
            if (!command.IsValidWith(_outstandingCommands))
            {
                return(false);
            }

            IImapCommand[] commandEnumerable = { command };
            if (!_outstandingCommands.All(c => c.IsValidWith(commandEnumerable)))
            {
                return(false);
            }

            return(true);
        }
Beispiel #4
0
        private IImapCommand CreateCommand(IReadOnlyList <IMessageData> data)
        {
            if (data.Count == 0)
            {
                throw new BadImapCommandFormatException(null);
            }

            var tagArg = data[0] as AtomMessageData;

            if (tagArg == null)
            {
                throw new BadImapCommandFormatException(null);
            }

            if (data.Count < 2)
            {
                throw new BadImapCommandFormatException(tagArg.Value);
            }

            var commandArg = data[1] as AtomMessageData;

            if (tagArg == null || commandArg == null)
            {
                throw new BadImapCommandFormatException(tagArg.Value);
            }

            if (!_commands.TryGetValue(commandArg.Value, out var command))
            {
                throw new BadImapCommandFormatException(tagArg.Value);
            }

            if (command.Metadata.MinimumState > State)
            {
                command.Value.Value.Dispose();
                throw new BadImapCommandFormatException(tagArg.Value);
            }

            IImapCommand imapCommand = command.Value.Value.Value;

            imapCommand.Initialize(commandArg.Value, tagArg.Value, data.Skip(2).ToImmutableList());
            return(imapCommand);
        }