On Mon, 09 Feb 2009 10:10:47 -0800 Robert Spier <rsp...@pobox.com>
wrote:

> 
> > Functionally, just about anything you can do here you can do just as
> > 
> > I don't see a problem with adding it per-se.  It'd make my
> > plugins/config file ordering a trifle simpler, but it doesn't
> > really add any functionality.  I agree there should be a big
> > warning about rejects/disconnects potentially being very dangerous.
> 
> Chris' analysis [mostly snipped] is compelling.
> 
> Karl, 
>   Can you update the patch with 
>      - documentation 
>      -   ... including a warning
>      - changing the name?
> 
>   And then I'll happily apply it.
> 
>   As Ask said, don't worry about bad english, that's easy enough to
>   fix later.
> 
> 
> -R

And voila. Hook renamed to data_headers_end, documentation in
README.plugins with a BIG warning.

$self->transaction->header($header) was moved earlier to have headers
in transaction object when we call the hook.

Regards.

-- 
Karl Y. Pradene
--- qpsmtpd/lib/Qpsmtpd/Plugin.pm	2009-02-08 16:28:37.434816850 +0100
+++ qpsmtpd-modif/lib/Qpsmtpd/Plugin.pm	2009-02-09 21:13:40.926806127 +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 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/README.plugins	2009-02-08 16:28:37.722814600 +0100
+++ qpsmtpd-modif/README.plugins	2009-02-09 22:01:45.914809383 +0100
@@ -150,6 +150,20 @@
              recommended)
 
 
+=head2 data_headers_end
+
+Hook after receiving all headers lines. Defaults to nothing,
+just continue processing. At this step, sender do not waiting for reply,
+but we can stop him for sending remainings datas by disconnect him.
+BE CAREFULL! If you drop the connection: legal MTAs will retry, spammers will probably not.
+This is not RFC compliant and can lead to unpredictable mess. Use with caution.
+
+Allowed return codes:
+
+  DENY_DISCONNECT     - Return '554 Message denied' and disconnect
+  DENYSOFT_DISCONNECT - Return '421 Message denied temporarily' and disconnect
+
+
 =head2 data_post
 
 Hook after receiving all data; just before the message is queued.
@@ -305,6 +319,7 @@
  config                        hook_config                      
  queue                         hook_queue                       
  data                          hook_data                        
+ data_headers_end              hook_data_headers_end
  data_post                     hook_data_post                   
  quit                          hook_quit                        
  rcpt                          hook_rcpt                        
--- qpsmtpd/lib/Qpsmtpd/SMTP.pm	2009-02-08 16:37:34.258805824 +0100
+++ qpsmtpd-modif/lib/Qpsmtpd/SMTP.pm	2009-02-09 22:09:36.182810551 +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('data_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 = '';

Reply via email to