On Fri, 17 Mar 2006 14:07:35 -0800
Ask Bjørn Hansen <ask@develooper.com> wrote:
Show quoted text> On Mar 16, 2006, at 10:38 PM, Hanno Hecker (via RT) wrote:
>
> I'd like to see a patch that makes a better API for reading the
> command and the command parameters. The default can still be having
> it space separated and provided in @_, but the hacks in mail() and
> rcpt() to read the rest aren't very nice so we should have an API to
> make it neater.
>
> Maybe just have a method to give the full unmodified command and use
> that, I don't know.
Ok, this is a first (draft of a ;->) patch. The Qpsmtpd::Command
contents can easily be moved to Qpsmtpd::SMTP if desired.
This patch adds some hooks:
* (helo|ehlo|mail|rcpt|auth|unrecognized_command)_parse:
i.e. all commands, which accept arguments (except VRFY).
these hooks get no arguments except
$self,$transaction/$connection
They MUST return(OK, \&ref_to_parsing_sub); to be the parser
for this command (in fact any return code from Constants.pm
which stops any other following plugin is ok).
The ref_to_parsing_sub() gets $self, $cmd, $line as arguments.
$self is here a Qpsmtpd::Command, which inherits from
Qpsmtpd::SMTP, so the usual $self->log(LOGDEBUG, "bla") stuff
works.
$cmd is the name of the command (i.e. the chars up to the first
space in the line from the client), $line the rest of the line.
This sub MUST return ($parsing_ok, $first, @param), like
the default
return($cmd, split(/ +/, $line));
The parse_addr_withhelo plugin enforces strict RFC 821 parsing,
which does not allow RCPT/MAIL parameters (a quick'n'dirty demo
plugin :-))
* (mail|rcpt)_pre
these hooks get $self,$transaction,$addr. $addr is the $first
from above.
Here the 'dont_require_angelbrackets' plugin adds the "<",">"
if not present to establish the current (i.e. without this patch)
behaviour of accepting addresses without the <>.
This (for example) can also be used to strip a trailing dot from an
address, if wanted
Docs will follow later if it's finished
Show quoted text> Also: Tests, please! It's pretty simple to add tests for "is the
> parsing working right".
ok, done.... sometimes it fails (but never from telnet to port 2525)
this seems to be a strange thing in 'make test'. Does 'make test' run
the commands in the same order every time?
Show quoted text> To add to the bikeshedding, I don't think it should be configurable
> -- it'd be fun to require them and see how it goes. If it doesn't
> work well, then just make them optional again and a rcpt_pre plugin
> can make them required for those who want that. Options in the core
> are bad, generally speaking.
hmm, ok, now we have a plugin which does exactly that... don't load ->
no addresses without brackets are accepted ;-)
Hanno