From 3fc545b7b0f5c9066324f3c5cf584f1840791586 Mon Sep 17 00:00:00 2001 From: Daniel Brahneborg Date: Mon, 7 Apr 2025 08:35:36 +0200 Subject: [PATCH] plugin/wordfilter: all global variables must be set in create_config --- plugins/wordfilter/wordfilter.pl | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/wordfilter/wordfilter.pl b/plugins/wordfilter/wordfilter.pl index dfcade2..8931c64 100644 --- a/plugins/wordfilter/wordfilter.pl +++ b/plugins/wordfilter/wordfilter.pl @@ -3,10 +3,9 @@ use POSIX qw(strftime); my $filename; my @words; -my $read_date = 0; - -my $debug = 1; -my $logfile = "/tmp/wordfilter.log"; +my $read_date; +my $debug; +my $logfile; sub dolog { my ($str) = @_; @@ -37,15 +36,18 @@ sub refresh_words { sub create_config { my ($name, $configdata) = @_; $filename = $configdata; + $read_date = 0; + $debug = 1; + $logfile = "/tmp/wordfilter.log"; } sub check { - my ($msg) = @_; + my ($id, $msg) = @_; refresh_words; foreach my $word (@words) { next unless ($msg =~ /\b${word}\b/); - dolog("reject message " . $q->{'ID'} . " containing `" . $word . "' in message: `" . $msg . "'\n"); + dolog("reject message " . $id . " containing `" . $word . "' in message: `" . $msg . "'\n"); return 8; } return 0; @@ -53,8 +55,8 @@ sub check { sub before_receive { my ($request, $response) = @_; - my $q = ${$request}{'qe'}; - my $msg = lc($q->{'MESSAGE'}); - return check($msg); + my $q = ${$request}{qe}; + my $msg = lc($q->{MESSAGE}); + return check($q->{ID}, $msg); }