develooper Front page | perl.cvs.qpsmtpd | Postings from April 2007

[svn:qpsmtpd] r731 - in trunk: . lib/Qpsmtpd

From:
msergeant
Date:
April 9, 2007 07:45
Subject:
[svn:qpsmtpd] r731 - in trunk: . lib/Qpsmtpd
Message ID:
20070409144514.58A17CB9B8@x12.develooper.com
Author: msergeant
Date: Mon Apr  9 07:45:11 2007
New Revision: 731

Modified:
   trunk/README.plugins
   trunk/lib/Qpsmtpd/Plugin.pm
   trunk/lib/Qpsmtpd/PollServer.pm
   trunk/lib/Qpsmtpd/SMTP.pm

Log:
Support for pluggable received headers


Modified: trunk/README.plugins
==============================================================================
--- trunk/README.plugins	(original)
+++ trunk/README.plugins	Mon Apr  9 07:45:11 2007
@@ -232,6 +232,24 @@
 
     - if we're in a connection, store things in the connection notes instead.
 
+=head2 received_line
+
+If you wish to provide your own Received header line, do it here.
+
+The hook is passed the following extra parameters (beyond $self and $transaction):
+
+ - $smtp - the SMTP type used (e.g. "SMTP" or "ESMTP").
+ - $auth - the Auth header additionals.
+ - $sslinfo - information about SSL for the header.
+
+You're free to use or discard any of the above.
+
+Allowed return codes:
+
+  OK, $string   - use this string for the Received header.
+  Anything Else - use the standard Received header.
+
+
 
 =head1 Include Files
 

Modified: trunk/lib/Qpsmtpd/Plugin.pm
==============================================================================
--- trunk/lib/Qpsmtpd/Plugin.pm	(original)
+++ trunk/lib/Qpsmtpd/Plugin.pm	Mon Apr  9 07:45:11 2007
@@ -9,7 +9,7 @@
     rcpt_parse rcpt_pre rcpt mail_parse mail mail_pre 
     data data_post queue_pre queue queue_post
     quit reset_transaction disconnect post-connection
-    unrecognized_command deny ok
+    unrecognized_command deny ok received_line
 );
 our %hooks = map { $_ => 1 } @hooks;
 

Modified: trunk/lib/Qpsmtpd/PollServer.pm
==============================================================================
--- trunk/lib/Qpsmtpd/PollServer.pm	(original)
+++ trunk/lib/Qpsmtpd/PollServer.pm	Mon Apr  9 07:45:11 2007
@@ -308,16 +308,24 @@
         $self->transaction->header($header);
     }
     
-    # only true if client authenticated
-    if ( $self->authenticated == OK ) { 
-        $header->add("X-Qpsmtpd-Auth","True");
+    my $smtp = $self->connection->hello eq "ehlo" ? "ESMTP" : "SMTP";
+    my $esmtp = substr($smtp,0,1) eq "E";
+    my $authheader;
+    my $sslheader;
+    
+    if (defined $self->connection->notes('tls_enabled')
+            and $self->connection->notes('tls_enabled'))
+    {
+        $smtp .= "S" if $esmtp; # RFC3848
+        $sslheader = "(".$self->connection->notes('tls_socket')->get_cipher()." encrypted) ";
+    }
+    
+    if (defined $self->{_auth} and $self->{_auth} == OK) {
+        $smtp .= "A" if $esmtp; # RFC3848
+        $authheader = "(smtp-auth username $self->{_auth_user}, mechanism $self->{_auth_mechanism})\n";
     }
     
-    $header->add("Received", "from ".$self->connection->remote_info
-                 ." (HELO ".$self->connection->hello_host . ") (".$self->connection->remote_ip
-                 . ")\n  by ".$self->config('me')." (qpsmtpd/".$self->version
-                 .") with $smtp; ". (strftime('%a, %d %b %Y %H:%M:%S %z', localtime)),
-                  0);
+    $header->add("Received", $self->received_line($smtp, $authheader, $sslheader), 0);
     
     return $self->respond(552, "Message too big!") if $self->{max_size} and $self->{data_size} > $self->{max_size};
     

Modified: trunk/lib/Qpsmtpd/SMTP.pm
==============================================================================
--- trunk/lib/Qpsmtpd/SMTP.pm	(original)
+++ trunk/lib/Qpsmtpd/SMTP.pm	Mon Apr  9 07:45:11 2007
@@ -673,11 +673,7 @@
     $authheader = "(smtp-auth username $self->{_auth_user}, mechanism $self->{_auth_mechanism})\n";
   }
 
-  $header->add("Received", "from ".$self->connection->remote_info
-               ." (HELO ".$self->connection->hello_host . ") (".$self->connection->remote_ip
-               . ")\n  $authheader  by ".$self->config('me')." (qpsmtpd/".$self->version
-               .") with $sslheader$smtp; ". (strftime('%a, %d %b %Y %H:%M:%S %z', localtime)),
-               0);
+  $header->add("Received", $self->received_line($smtp, $authheader, $sslheader), 0);
 
   # if we get here without seeing a terminator, the connection is
   # probably dead.
@@ -697,6 +693,23 @@
   $self->run_hooks("data_post");
 }
 
+sub received_line {
+  my ($self, $smtp, $authheader, $sslheader) = @_;
+  my ($rc, $received) = $self->run_hooks("received_line", $smtp, $authheader, $sslheader);
+  if ($rc == YIELD) {
+    die "YIELD not supported for received_line hook";
+  }
+  elsif ($rc == OK) {
+    return $received;
+  }
+  else { # assume $rc == DECLINED
+    return  "from ".$self->connection->remote_info
+           ." (HELO ".$self->connection->hello_host . ") (".$self->connection->remote_ip
+           . ")\n  $authheader  by ".$self->config('me')." (qpsmtpd/".$self->version
+           .") with $sslheader$smtp; ". (strftime('%a, %d %b %Y %H:%M:%S %z', localtime))
+  }
+}
+
 sub data_post_respond {
   my ($self, $rc, $msg, $args) = @_;
   if ($rc == DONE) {



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About