private async Task <ISmtpCommand> GetCommandAsync(CancellationToken token) { string line = await _connection.ReadLineAsync(Encoding.UTF8, token); _log.Verbose($"SMTP <- {line}"); if (line.Length < 4) { await this.SendReplyAsync(SmtpReplyCode.SyntaxError, "No command found", token); return(null); } int spaceIndex = line.IndexOf(" ", StringComparison.Ordinal); string command; string arguments; if (spaceIndex == -1) { command = line; arguments = null; } else { command = line.Substring(0, spaceIndex).ToUpperInvariant(); arguments = line.Substring(spaceIndex + 1); } var commandExecutor = _context.ResolveOptionalKeyed <ISmtpCommand>(command); if (commandExecutor == null) { await this.SendReplyAsync(SmtpReplyCode.SyntaxError, "Command not implemented", token); return(null); } commandExecutor.Initialize(arguments); return(commandExecutor); }
public Task <byte[]> ReadAuthenticationFragmentAsync(CancellationToken cancellationToken) { return(_connection.ReadLineAsync(Encoding.ASCII, cancellationToken) .ContinueWith(t => Convert.FromBase64String(t.Result), cancellationToken)); }