From 5ea1eb0f4c2d6f9cf1c1f125838c00d3d4010361 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 22 Jun 2012 23:56:25 -0400 Subject: [PATCH] badrcptto: log tweaks, better regex detection --- plugins/check_badrcptto | 6 +++--- t/plugin_tests/check_badrcptto | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/check_badrcptto b/plugins/check_badrcptto index 7b5f7d9..8787974 100644 --- a/plugins/check_badrcptto +++ b/plugins/check_badrcptto @@ -47,7 +47,7 @@ use Qpsmtpd::Constants; use Qpsmtpd::DSN; sub hook_rcpt { - my ($self, $transaction, $recipient, %param) = @_; + my ($self, $transaction, $recipient, %param) = @_; return (DECLINED) if $self->is_immune(); @@ -55,7 +55,7 @@ sub hook_rcpt { or return (DECLINED); my @badrcptto = $self->qp->config("badrcptto") or do { - $self->log(LOGINFO, "skip: empty config"); + $self->log(LOGINFO, "skip, empty config"); return (DECLINED); }; @@ -79,7 +79,7 @@ sub hook_rcpt { sub is_match { my ( $self, $to, $bad, $host ) = @_; - if ( $bad =~ /[\/\^\$\*\+\!\%]/ ) { # it's a regexp + if ( $bad =~ /[\/\^\$\*\+\!\%\?\\]/ ) { # it's a regexp $self->log(LOGDEBUG, "badmailfrom pattern ($bad) match for $to"); if ( $to =~ /$bad/i ) { $self->log(LOGINFO, 'fail: pattern match'); diff --git a/t/plugin_tests/check_badrcptto b/t/plugin_tests/check_badrcptto index ac9057d..3e7c9a3 100644 --- a/t/plugin_tests/check_badrcptto +++ b/t/plugin_tests/check_badrcptto @@ -13,6 +13,14 @@ sub register_tests { $self->register_test("test_get_host_and_to", 8); } +sub _reset_connection_flags { + my $self = shift; + $self->qp->connection->relay_client(0); + $self->qp->connection->notes('whitelisthost', 0); + $self->connection->notes('naughty',0); + $self->connection->notes('rejected', 0); +}; + sub test_is_match { my $self = shift; @@ -52,19 +60,21 @@ sub test_is_match { sub test_hook_rcpt { my $self = shift; + $self->_reset_connection_flags(); + my $transaction = $self->qp->transaction; my $recipient = Qpsmtpd::Address->new( '' ); my ($r, $mess) = $self->hook_rcpt( $transaction, $recipient ); - cmp_ok( DECLINED, '==', $r, "valid +"); + cmp_ok( $r, '==', DECLINED, "valid +"); $recipient = Qpsmtpd::Address->new( '' ); ($r, $mess) = $self->hook_rcpt( $transaction, $recipient ); - cmp_ok( DENY, '==', $r, "bad match, +"); + cmp_ok( $r, '==', DENY, "bad match, +, $mess"); $recipient = Qpsmtpd::Address->new( '' ); ($r, $mess) = $self->hook_rcpt( $transaction, $recipient ); - cmp_ok( DENY, '==', $r, "bad host match, +"); + cmp_ok( $r, '==', DENY, "bad host match, +, $mess"); }; sub test_get_host_and_to {