From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: Dominik Csapak <d.csapak@proxmox.com>
Cc: pmg-devel@lists.proxmox.com
Subject: Re: [pmg-devel] [PATCH pmg-api 1/3] refactor domain_regex to Utils
Date: Tue, 17 Nov 2020 14:18:30 +0100 [thread overview]
Message-ID: <20201117141830.427e1554@rosa.proxmox.com> (raw)
In-Reply-To: <20201117080513.15046-2-d.csapak@proxmox.com>
On Tue, 17 Nov 2020 09:05:10 +0100
Dominik Csapak <d.csapak@proxmox.com> wrote:
> we will need this somewhere else later
>
> Signed-off-by: Dominik Csapak <d.csapak@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;
next prev parent reply other threads:[~2020-11-17 13:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-17 8:05 [pmg-devel] [PATCH pmg-api/gui] add quarantine self service button Dominik Csapak
2020-11-17 8:05 ` [pmg-devel] [PATCH pmg-api 1/3] refactor domain_regex to Utils Dominik Csapak
2020-11-17 13:18 ` Stoiko Ivanov [this message]
2020-11-17 8:05 ` [pmg-devel] [PATCH pmg-api 2/3] add 'quarantinelink' to admin config Dominik Csapak
2020-11-17 13:20 ` Stoiko Ivanov
2020-11-17 8:05 ` [pmg-devel] [PATCH pmg-api 3/3] api2/quarantine: add global sendlink api call Dominik Csapak
2020-11-17 8:05 ` [pmg-devel] [PATCH pmg-gui 1/1] add 'Request Quarantine Link' Button to LoginView Dominik Csapak
2020-11-17 13:27 ` Stoiko Ivanov
2020-11-17 13:16 ` [pmg-devel] [PATCH pmg-api/gui] add quarantine self service button Stoiko Ivanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201117141830.427e1554@rosa.proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=d.csapak@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox