]> git.proxmox.com Git - pmg-api.git/commitdiff
refactor domain_regex to Utils
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 18 Nov 2020 10:59:34 +0000 (11:59 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 18 Nov 2020 16:04:38 +0000 (17:04 +0100)
we will need this somewhere else later

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PMG/CLI/pmgqm.pm
src/PMG/Utils.pm

index 937269f510684b8ee03ce515ecf2ba780ce1026f..39253dbfe0ae632798b2c537acae3f50a538a875 100755 (executable)
@@ -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;
index c5cf7b8625219fe83e688e6476723b530b59867a..8a7021dc9fe40f7f25c85fd879ffec837427a669 100644 (file)
@@ -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;
+}
+
+
 1;