public bool TryMakeMail(TokenEnumerator enumerator, out SmtpCommand command, out SmtpResponse errorResponse)
{
Debug.Assert(enumerator.Peek() == new Token(TokenKind.Text, "MAIL"));
command = null;
errorResponse = null;
enumerator.Take();
enumerator.TakeWhile(TokenKind.Space);
if (enumerator.Take() != new Token(TokenKind.Text, "FROM") || enumerator.Take() != new Token(TokenKind.Punctuation, ":"))
{
errorResponse = new SmtpResponse(SmtpReplyCode.SyntaxError, "missing the FROM:");
return false;
}
// according to the spec, whitespace isnt allowed here but most servers send it
enumerator.TakeWhile(TokenKind.Space);
IMailbox mailbox;
if (_parser.TryMakeReversePath(enumerator, out mailbox) == false)
{
_logger.LogVerbose("Syntax Error (Text={0})", enumerator.AsText());
errorResponse = new SmtpResponse(SmtpReplyCode.SyntaxError);
return false;
}
// match the optional (ESMTP) parameters
IDictionary<string, string> parameters;
if (_parser.TryMakeMailParameters(enumerator, out parameters) == false)
{
parameters = new Dictionary<string, string>();
}
command = new MailCommand(mailbox, parameters, _options.MailboxFilterFactory);
return true;
}