Skip to content
This repository
Browse code

Support for pluggable received headers

git-svn-id: http://svn.perl.org/qpsmtpd/trunk@731 958fd67b-6ff1-0310-b445-bb7760255be9
  • Loading branch information...
commit 8aa98e9dd644bc61fae0eeeef3598b4d540a1848 1 parent 9c807ff
msergeant authored
18 README.plugins
@@ -232,6 +232,24 @@ in
232 232
233 233 - if we're in a connection, store things in the connection notes instead.
234 234
  235 +=head2 received_line
  236 +
  237 +If you wish to provide your own Received header line, do it here.
  238 +
  239 +The hook is passed the following extra parameters (beyond $self and $transaction):
  240 +
  241 + - $smtp - the SMTP type used (e.g. "SMTP" or "ESMTP").
  242 + - $auth - the Auth header additionals.
  243 + - $sslinfo - information about SSL for the header.
  244 +
  245 +You're free to use or discard any of the above.
  246 +
  247 +Allowed return codes:
  248 +
  249 + OK, $string - use this string for the Received header.
  250 + Anything Else - use the standard Received header.
  251 +
  252 +
235 253
236 254 =head1 Include Files
237 255
2  lib/Qpsmtpd/Plugin.pm
@@ -9,7 +9,7 @@ our @hooks = qw(
9 9 rcpt_parse rcpt_pre rcpt mail_parse mail mail_pre
10 10 data data_post queue_pre queue queue_post
11 11 quit reset_transaction disconnect post-connection
12   - unrecognized_command deny ok
  12 + unrecognized_command deny ok received_line
13 13 );
14 14 our %hooks = map { $_ => 1 } @hooks;
15 15
24 lib/Qpsmtpd/PollServer.pm
@@ -308,16 +308,24 @@ sub end_of_data {
308 308 $self->transaction->header($header);
309 309 }
310 310
311   - # only true if client authenticated
312   - if ( $self->authenticated == OK ) {
313   - $header->add("X-Qpsmtpd-Auth","True");
  311 + my $smtp = $self->connection->hello eq "ehlo" ? "ESMTP" : "SMTP";
  312 + my $esmtp = substr($smtp,0,1) eq "E";
  313 + my $authheader;
  314 + my $sslheader;
  315 +
  316 + if (defined $self->connection->notes('tls_enabled')
  317 + and $self->connection->notes('tls_enabled'))
  318 + {
  319 + $smtp .= "S" if $esmtp; # RFC3848
  320 + $sslheader = "(".$self->connection->notes('tls_socket')->get_cipher()." encrypted) ";
  321 + }
  322 +
  323 + if (defined $self->{_auth} and $self->{_auth} == OK) {
  324 + $smtp .= "A" if $esmtp; # RFC3848
  325 + $authheader = "(smtp-auth username $self->{_auth_user}, mechanism $self->{_auth_mechanism})\n";
314 326 }
315 327
316   - $header->add("Received", "from ".$self->connection->remote_info
317   - ." (HELO ".$self->connection->hello_host . ") (".$self->connection->remote_ip
318   - . ")\n by ".$self->config('me')." (qpsmtpd/".$self->version
319   - .") with $smtp; ". (strftime('%a, %d %b %Y %H:%M:%S %z', localtime)),
320   - 0);
  328 + $header->add("Received", $self->received_line($smtp, $authheader, $sslheader), 0);
321 329
322 330 return $self->respond(552, "Message too big!") if $self->{max_size} and $self->{data_size} > $self->{max_size};
323 331
23 lib/Qpsmtpd/SMTP.pm
@@ -673,11 +673,7 @@ sub data_respond {
673 673 $authheader = "(smtp-auth username $self->{_auth_user}, mechanism $self->{_auth_mechanism})\n";
674 674 }
675 675
676   - $header->add("Received", "from ".$self->connection->remote_info
677   - ." (HELO ".$self->connection->hello_host . ") (".$self->connection->remote_ip
678   - . ")\n $authheader by ".$self->config('me')." (qpsmtpd/".$self->version
679   - .") with $sslheader$smtp; ". (strftime('%a, %d %b %Y %H:%M:%S %z', localtime)),
680   - 0);
  676 + $header->add("Received", $self->received_line($smtp, $authheader, $sslheader), 0);
681 677
682 678 # if we get here without seeing a terminator, the connection is
683 679 # probably dead.
@@ -697,6 +693,23 @@ sub data_respond {
697 693 $self->run_hooks("data_post");
698 694 }
699 695
  696 +sub received_line {
  697 + my ($self, $smtp, $authheader, $sslheader) = @_;
  698 + my ($rc, $received) = $self->run_hooks("received_line", $smtp, $authheader, $sslheader);
  699 + if ($rc == YIELD) {
  700 + die "YIELD not supported for received_line hook";
  701 + }
  702 + elsif ($rc == OK) {
  703 + return $received;
  704 + }
  705 + else { # assume $rc == DECLINED
  706 + return "from ".$self->connection->remote_info
  707 + ." (HELO ".$self->connection->hello_host . ") (".$self->connection->remote_ip
  708 + . ")\n $authheader by ".$self->config('me')." (qpsmtpd/".$self->version
  709 + .") with $sslheader$smtp; ". (strftime('%a, %d %b %Y %H:%M:%S %z', localtime))
  710 + }
  711 +}
  712 +
700 713 sub data_post_respond {
701 714 my ($self, $rc, $msg, $args) = @_;
702 715 if ($rc == DONE) {

0 comments on commit 8aa98e9

Please sign in to comment.
Something went wrong with that request. Please try again.