Qpsmtpd::Command(3) parse arguments to SMTP commands


Qpsmtpd::Command provides just one public sub routine: parse().

This sub expects two or three arguments. The first is the name of the SMTP command (such as HELO, MAIL, ...). The second must be the remaining of the line the client sent.

If no third argument is given (or it's not a reference to a CODE) it parses the line according to RFC 1869 (SMTP Service Extensions) for the MAIL and RCPT commands and splitting by spaces (`` '') for all other.

Any module can supply it's own parsing routine by returning a sub routine reference from a hook_*_parse. This sub will be called with $self, $cmd and $line.

On successfull parsing it MUST return OK (the constant from Qpsmtpd::Constants) success as first argument and a list of values, which will be the arguments to the hook for this command.

If parsing failed, the second returned value (if any) will be returned to the client as error message.


Inside a plugin

 sub hook_unrecognized_command_parse {
    my ($self, $transaction, $cmd) = @_;
    return (OK, \&bdat_parser) if ($cmd eq 'bdat');
 sub bdat_parser {
    my ($self,$cmd,$line) = @_;
    # .. do something with $line...
    return (DENY, "Invalid arguments") 
      if $some_reason_why_there_is_a_syntax_error;
    return (OK, @args);
 sub hook_unrecognized_command {
    my ($self, $transaction, $cmd, @args) = @_;
    return (DECLINED) if ($self->qp->connection->hello eq 'helo');
    return (DECLINED) unless ($cmd eq 'bdat');