SmtpServer.Protocol.SmtpCommandFactory.TryMakeAuth C# (CSharp) Method

TryMakeAuth() public method

Make an AUTH command from the given enumerator.
public TryMakeAuth ( TokenEnumerator enumerator, SmtpCommand &command, SmtpResponse &errorResponse ) : bool
enumerator SmtpServer.Protocol.Text.TokenEnumerator The enumerator to create the command from.
command SmtpCommand The AUTH command that is defined within the token enumerator.
errorResponse SmtpResponse The error that indicates why the command could not be made.
return bool
        public bool TryMakeAuth(TokenEnumerator enumerator, out SmtpCommand command, out SmtpResponse errorResponse)
        {
            Debug.Assert(enumerator.Peek() == new Token(TokenKind.Text, "AUTH"));

            command = null;
            errorResponse = null;

            enumerator.Take();
            enumerator.TakeWhile(TokenKind.Space);

            AuthenticationMethod method;
            if (Enum.TryParse(enumerator.Peek().Text, true, out method) == false)
            {
                _logger.LogVerbose("AUTH command requires a valid method (PLAIN or LOGIN)");

                errorResponse = SmtpResponse.SyntaxError;
                return false;
            }

            enumerator.Take();

            string parameter = null;
            if (enumerator.Count > 0 && _parser.TryMakeBase64(enumerator, out parameter) == false)
            {
                _logger.LogVerbose("AUTH parameter must be a Base64 encoded string");

                errorResponse = SmtpResponse.SyntaxError;
                return false;
            }

            command = new AuthCommand(_options.UserAuthenticator, method, parameter);
            return true;
        }
    }