Support for pluggable received headers
git-svn-id: https://svn.perl.org/qpsmtpd/trunk@731 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
parent
eb8a190e44
commit
062e73b7bf
@ -232,6 +232,24 @@ in
|
||||
|
||||
- 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
|
||||
|
||||
|
@ -9,7 +9,7 @@ our @hooks = qw(
|
||||
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;
|
||||
|
||||
|
@ -308,16 +308,24 @@ sub end_of_data {
|
||||
$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) ";
|
||||
}
|
||||
|
||||
$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);
|
||||
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", $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};
|
||||
|
||||
|
@ -673,11 +673,7 @@ sub data_respond {
|
||||
$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 @@ sub data_respond {
|
||||
$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) {
|
||||
|
Loading…
Reference in New Issue
Block a user