From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 8FC9860631 for ; Tue, 17 Nov 2020 14:19:02 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8524D11353 for ; Tue, 17 Nov 2020 14:18:32 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 6676111343 for ; Tue, 17 Nov 2020 14:18:31 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2D4B1436FE for ; Tue, 17 Nov 2020 14:18:31 +0100 (CET) Date: Tue, 17 Nov 2020 14:18:30 +0100 From: Stoiko Ivanov To: Dominik Csapak Cc: pmg-devel@lists.proxmox.com Message-ID: <20201117141830.427e1554@rosa.proxmox.com> In-Reply-To: <20201117080513.15046-2-d.csapak@proxmox.com> References: <20201117080513.15046-1-d.csapak@proxmox.com> <20201117080513.15046-2-d.csapak@proxmox.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.087 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [pmgqm.pm, utils.pm] Subject: Re: [pmg-devel] [PATCH pmg-api 1/3] refactor domain_regex to Utils X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Nov 2020 13:19:02 -0000 On Tue, 17 Nov 2020 09:05:10 +0100 Dominik Csapak wrote: > we will need this somewhere else later > > Signed-off-by: Dominik Csapak > --- > src/PMG/CLI/pmgqm.pm | 29 ++--------------------------- > src/PMG/Utils.pm | 26 ++++++++++++++++++++++++++ > 2 files changed, 28 insertions(+), 27 deletions(-) > > diff --git a/src/PMG/CLI/pmgqm.pm b/src/PMG/CLI/pmgqm.pm > index 937269f..39253db 100755 > --- a/src/PMG/CLI/pmgqm.pm > +++ b/src/PMG/CLI/pmgqm.pm > @@ -33,31 +33,6 @@ sub setup_environment { > PMG::RESTEnvironment->setup_default_cli_env(); > } > > -sub domain_regex { > - my ($domains) = @_; > - > - my @ra; > - foreach my $d (@$domains) { > - # skip domains with non-DNS name characters > - next if $d =~ m/[^A-Za-z0-9\-\.]/; > - if ($d =~ m/^\.(.*)$/) { > - my $dom = $1; > - $dom =~ s/\./\\\./g; > - push @ra, $dom; > - push @ra, "\.\*\\.$dom"; > - } else { > - $d =~ s/\./\\\./g; > - push @ra, $d; > - } > - } > - > - my $re = join ('|', @ra); > - > - my $regex = qr/\@($re)$/i; > - > - return $regex; > -} > - > sub get_item_data { > my ($data, $ref) = @_; > > @@ -145,7 +120,7 @@ __PACKAGE__->register_method ({ > my $dbh = PMG::DBTools::open_ruledb(); > > my $domains = PVE::INotify::read_file('domains'); > - my $domainregex = domain_regex([keys %$domains]); > + my $domainregex = PMG::Utils::domain_regex([keys %$domains]); > > my $sth = $dbh->prepare( > "SELECT pmail, AVG(spamlevel) as spamlevel, count(*) FROM CMailStore, CMSReceivers " . > @@ -278,7 +253,7 @@ __PACKAGE__->register_method ({ > } > > my $domains = PVE::INotify::read_file('domains'); > - my $domainregex = domain_regex([keys %$domains]); > + my $domainregex = PMG::Utils::domain_regex([keys %$domains]); > > my $template = "spamreport-${reportstyle}.tt"; > my $found = 0; > diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm > index d0654e1..a04d41b 100644 > --- a/src/PMG/Utils.pm > +++ b/src/PMG/Utils.pm > @@ -1417,4 +1417,30 @@ sub reload_smtp_filter { > return kill (10, $pid); # send SIGUSR1 > } > > +sub domain_regex { > + my ($domains) = @_; > + > + my @ra; > + foreach my $d (@$domains) { > + # skip domains with non-DNS name characters > + next if $d =~ m/[^A-Za-z0-9\-\.]/; > + if ($d =~ m/^\.(.*)$/) { > + my $dom = $1; > + $dom =~ s/\./\\\./g; > + push @ra, $dom; > + push @ra, "\.\*\\.$dom"; > + } else { > + $d =~ s/\./\\\./g; > + push @ra, $d; > + } > + } > + > + my $re = join ('|', @ra); > + > + my $regex = qr/\@($re)$/i; > + > + return $regex; > +} > + > + nit: since pmgqm has a use statement for PMG::API2::Quarantine, we could also move it there - but since all of it is in the same repository I don't think it makes such a difference. also: one extra newline > 1;