[pmg-devel] [PATCH pmg-api 1/3] refactor domain_regex to Utils
Stoiko Ivanov
s.ivanov at proxmox.com
Tue Nov 17 14:18:30 CET 2020
On Tue, 17 Nov 2020 09:05:10 +0100
Dominik Csapak <d.csapak at proxmox.com> wrote:
> we will need this somewhere else later
>
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> 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;
More information about the pmg-devel
mailing list