On Sat, 7 Feb 2009 23:24:39 -0800 Ask Bjørn Hansen <a...@develooper.com> wrote:
> > On Feb 7, 2009, at 6:25, Karl Y. Pradene wrote: > > > Hi, > > is it possible add a hook at the end of headers? > > Hi Karl, > > Look in data_respond in lib/Qpsmtpd/SMTP.pm -- it would be pretty > easy to add. Look for the line that says "$in_header = 0;" > > I'm not sure it'd be useful though, because the only way you can > avoid receiving the data anyway at that point would be just dropping > the connection -- and well behaved mailers will just try and try > again after that. > > Of course if it's spam or a virus it's unlikely to reconnect more or > less because you drop the connection, so I guess that it could be > worthwhile... > > > - ask > Here the two patches I made. -- Karl Y. Pradene
--- qpsmtpd/lib/Qpsmtpd/Plugin.pm 2009-02-08 16:28:37.434816850 +0100 +++ qpsmtpd-modif/lib/Qpsmtpd/Plugin.pm 2009-02-08 17:20:56.640056737 +0100 @@ -7,7 +7,7 @@ logging config post-fork pre-connection connect ehlo_parse ehlo helo_parse helo auth_parse auth auth-plain auth-login auth-cram-md5 rcpt_parse rcpt_pre rcpt mail_parse mail mail_pre - data data_post queue_pre queue queue_post vrfy noop + data headers_end data_post queue_pre queue queue_post vrfy noop quit reset_transaction disconnect post-connection unrecognized_command deny ok received_line help );
--- qpsmtpd/lib/Qpsmtpd/SMTP.pm 2009-02-08 16:37:34.258805824 +0100 +++ qpsmtpd-modif/lib/Qpsmtpd/SMTP.pm 2009-02-08 17:20:58.250806860 +0100 @@ -664,8 +664,16 @@ $buffer = ""; - # FIXME - call plugins to work on just the header here; can - # save us buffering the mail content. + $self->transaction->header($header); + ($rc, $msg) = $self->run_hooks('headers_end') ; + elsif ($rc == DENY_DISCONNECT) { + $self->respond(554, $msg || "Message denied"); + $self->disconnect; + return 1 ; } + elsif ($rc == DENYSOFT_DISCONNECT) { + $self->respond(421, $msg || "Message denied temporarily"); + $self->disconnect; + return 1 ; } # Save the start of just the body itself $self->transaction->set_body_start(); @@ -687,8 +695,6 @@ $self->log(LOGDEBUG, "max_size: $max_size / size: $size"); - $self->transaction->header($header); - my $smtp = $self->connection->hello eq "ehlo" ? "ESMTP" : "SMTP"; my $esmtp = substr($smtp,0,1) eq "E"; my $authheader = '';