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;
}
}