Plugin.pm: more descriptive variable names

append optional log_mess to log entry (more description)
subsequent attempts to set naughty don't overwrite the first
set the naughty rejection type to be the reject type of the plugin that marked the connection naughty
get_reject_type can be passed an explicit default
This commit is contained in:
Matt Simerson 2012-06-22 18:14:44 -04:00
parent c1df6c2e1f
commit d5ccedd37e

View File

@ -212,32 +212,37 @@ sub compile {
sub get_reject { sub get_reject {
my $self = shift; my $self = shift;
my $message = shift || "why didn't you pass an error message?"; my $smtp_mess = shift || "why didn't you pass an error message?";
my $log_info = shift || ''; my $log_mess = shift || '';
$log_info = ", $log_info" if $log_info; $log_mess = ", $log_mess" if $log_mess;
my $reject = $self->{_args}{reject}; my $reject = $self->{_args}{reject};
if ( defined $reject && ! $reject ) { if ( defined $reject && ! $reject ) {
$self->log(LOGINFO, 'fail, reject disabled'); $self->log(LOGINFO, "fail, reject disabled" . $log_mess);
return DECLINED; return DECLINED;
}; };
# the naughty plugin will reject later # the naughty plugin will reject later
if ( $reject eq 'naughty' ) { if ( $reject eq 'naughty' ) {
$self->log(LOGINFO, 'fail, NAUGHTY'); $self->log(LOGINFO, "fail, NAUGHTY" . $log_mess);
$self->connection->notes('naughty', $message); if ( ! $self->connection->notes('naughty') ) {
$self->connection->notes('naughty', $smtp_mess);
};
if ( ! $self->connection->notes('naughty_reject_type') ) {
$self->connection->notes('naughty_reject_type', $self->{_args}{reject_type} );
}
return (DECLINED); return (DECLINED);
}; };
# they asked for reject, we give them reject # they asked for reject, we give them reject
$self->log(LOGINFO, 'fail'.$log_info); $self->log(LOGINFO, "fail" . $log_mess);
return ( $self->get_reject_type(), $message); return ( $self->get_reject_type(), $smtp_mess);
}; };
sub get_reject_type { sub get_reject_type {
my $self = shift; my $self = shift;
my $default = shift || DENY; my $default = shift || DENY;
my $deny = $self->{_args}{reject_type} or return $default; my $deny = shift || $self->{_args}{reject_type} or return $default;
return $deny =~ /^(temp|soft)$/i ? DENYSOFT return $deny =~ /^(temp|soft)$/i ? DENYSOFT
: $deny =~ /^(perm|hard)$/i ? DENY : $deny =~ /^(perm|hard)$/i ? DENY