From 4ee8b164f9e09a0e10be3334d972a1ce2374a4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Sun, 8 Sep 2002 09:58:47 +0000 Subject: [PATCH] support more data_post hook return codes eval { } the hooks so we can handle them failing more gracefully (not sure if this really adds anything... hmn). git-svn-id: https://svn.perl.org/qpsmtpd/branches/v010@48 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Qpsmtpd.pm | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index c2629c6..08466c4 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -312,7 +312,8 @@ sub data { $i++; $self->respond(451, "See http://develooper.com/code/qpsmtpd/barelf.html"), exit if $_ eq ".\n"; - unless ($self->transaction->blocked and ($max_size and $size > $max_size)) { + # add a transaction->blocked check back here when we have line by line plugin access... + unless (($max_size and $size > $max_size)) { s/\r\n$/\n/; if ($in_header and m/^\s*$/) { $in_header = 0; @@ -361,14 +362,25 @@ sub data { # probably dead. $self->respond(451, "Incomplete DATA"), return 1 unless $complete; - $self->respond(550, $self->transaction->blocked),return 1 if ($self->transaction->blocked); + #$self->respond(550, $self->transaction->blocked),return 1 if ($self->transaction->blocked); $self->respond(552, "Message too big!"),return 1 if $max_size and $size > $max_size; my ($rc, $msg) = $self->run_hooks("data_post"); - if ($rc != DONE) { + if ($rc == DONE) { + return 1; + } + elsif ($rc == DENY) { + $self->respond(552, $msg || "Message denied"); + } + elsif ($rc == DENYSOFT) { + $self->respond(452, $msg || "Message denied temporarily"); + } + else { return $self->queue($self->transaction); } + + } sub queue { @@ -379,7 +391,7 @@ sub queue { pipe(ENVELOPE_READER, ENVELOPE_WRITER) or fault("Could not create envelope pipe"), exit; my $child = fork(); - + not defined $child and fault(451, "Could not fork"), exit; if ($child) { @@ -469,6 +481,7 @@ sub load_plugins { "require Qpsmtpd::Plugin;", 'use vars qw(@ISA);', '@ISA = qw(Qpsmtpd::Plugin);', + "sub plugin_name { qq[$plugin_name] }", $line, $sub, "\n", # last line comment without newline? @@ -493,7 +506,9 @@ sub run_hooks { if ($self->{_hooks}->{$hook}) { my @r; for my $code (@{$self->{_hooks}->{$hook}}) { - (@r) = &{$code}($self->transaction, @_); + eval { (@r) = &{$code}($self->transaction, @_); }; + $@ and $self->log(0, "FATAL PLUGIN ERROR: ", $@) and next; + $self->log(1, "a $hook hook returned undef!") and next unless defined $r[0]; last unless $r[0] == DECLINED; } return @r;