Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

badmailfrom: allow selective rejection

default handling preserved.
adds ability to disable rejection or handle via naughty
  • Loading branch information...
commit 3a6d87f54c19c020f5983d7845ad3f3fb21b4a29 1 parent 90f4dc4
@msimerson authored
Showing with 37 additions and 7 deletions.
  1. +37 −7 plugins/check_badmailfrom
View
44 plugins/check_badmailfrom
@@ -17,6 +17,20 @@ listed in badmailfrom. A line in badmailfrom may be of the form
You may include an optional message after the sender address (leave a space),
to be used when rejecting the sender.
+=head1 CONFIGURATION
+
+=head2 reject
+
+ badmailfrom reject [ 0 | 1 | naughty ]
+
+I<0> will not reject any connections.
+
+I<1> will reject naughty senders.
+
+I<connect> is the most efficient setting. It's also the default.
+
+To reject at any other connection hook, use the I<naughty> setting and the
+B<naughty> plugin.
=head1 PATTERNS
@@ -42,14 +56,27 @@ stage, so store it until later.
=head1 AUTHORS
-initial author of badmailfrom - Jim Winstead
+2002 - Jim Winstead - initial author of badmailfrom
-pattern matching plugin - Johan Almqvist <johan-qpsmtpd@almqvist.net>
+2010 - Johan Almqvist <johan-qpsmtpd@almqvist.net> - pattern matching plugin
-merging of the two and plugin tests - Matt Simerson <matt@tnpi.net>
+2012 - Matt Simerson - merging of the two and plugin tests
=cut
+sub register {
+ my ($self,$qp) = shift, shift;
+ $self->{_args} = { @_ };
+
+ # preserve legacy "reject during rcpt" behavior
+ $self->{_args}{reject} = 1 if ! defined $self->{_args}{reject};
+
+ return if ! $self->{_args}{reject}; # reject 0, log only
+ return if $self->{_args}{reject} eq 'naughty'; # naughty will reject
+
+ $self->register_hook('rcpt', 'rcpt_handler');
+};
+
sub hook_mail {
my ($self, $transaction, $sender, %param) = @_;
@@ -69,8 +96,11 @@ sub hook_mail {
next unless $bad;
next unless $self->is_match( $from, $bad, $host );
$reason ||= "Your envelope sender is in my badmailfrom list";
- $transaction->notes('badmailfrom', $reason);
+ $self->connection->notes('naughty', $reason);
}
+ if ( ! $self->connection->notes('naughty') ) {
+ $self->log(LOGINFO, "pass");
+ };
return DECLINED;
}
@@ -96,11 +126,11 @@ sub is_match {
return 1;
};
-sub hook_rcpt {
+sub rcpt_handler {
my ($self, $transaction, $rcpt, %param) = @_;
- my $note = $transaction->notes('badmailfrom') or return (DECLINED);
+ my $note = $self->connection->notes('naughty') or return (DECLINED);
- $self->log(LOGINFO, $note);
+ $self->log(LOGINFO, "fail, $note");
return (DENY, $note);
}
Please sign in to comment.
Something went wrong with that request. Please try again.