public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api 1/1] api: quarantine: include positive and negative spam score sum in list
Date: Mon, 22 Sep 2025 10:05:00 +0200	[thread overview]
Message-ID: <20250922080509.737332-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250922080509.737332-1-d.csapak@proxmox.com>

This can be useful information, so to show it in the web ui, we have to
return it in the api here.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/PMG/API2/Quarantine.pm | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/PMG/API2/Quarantine.pm b/src/PMG/API2/Quarantine.pm
index 3887a74..2464ee7 100644
--- a/src/PMG/API2/Quarantine.pm
+++ b/src/PMG/API2/Quarantine.pm
@@ -91,6 +91,29 @@ sub decode_spaminfo {
     return $res;
 }
 
+# parses and returns the sum of the positive and negative spam rule matches, so
+# we can show them individually
+sub get_spamscores { my ($info) = @_;
+
+    return (0, 0) if !defined($info);
+
+    my $positive = 0;
+    my $negative = 0;
+
+    foreach my $test (split(',', $info)) {
+        my ($name, $score) = split(':', $test);
+
+        $score = $score + 0;
+        if ($score > 0) {
+            $positive += $score;
+        } else {
+            $negative += $score;
+        }
+    }
+
+    return ($positive, $negative);
+}
+
 my $extract_email = sub {
     my $data = shift;
 
@@ -149,6 +172,9 @@ my $parse_header_info = sub {
     $res->{id} = 'C' . $ref->{cid} . 'R' . $ref->{rid} . 'T' . $ref->{ticketid};
     $res->{time} = $ref->{time};
     $res->{bytes} = $ref->{bytes};
+    my ($positive, $negative) = get_spamscores($ref->{info});
+    $res->{'score-positive'} = $positive;
+    $res->{'score-negative'} = $negative;
 
     my $qtype = $ref->{qtype};
 
@@ -880,6 +906,14 @@ __PACKAGE__->register_method({
                     description => "Spam score.",
                     type => 'number',
                 },
+                'score-positive' => {
+                    description => "Sum of positive spam score matches.",
+                    type => 'number',
+                },
+                'score-negative' => {
+                    description => "Sum of negative spam score matches.",
+                    type => 'number',
+                },
             },
         },
     },
-- 
2.47.3



_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel


  reply	other threads:[~2025-09-22  8:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-22  8:04 [pmg-devel] [PATCH pmg-api/pmg-gui 0/2] spam quarantine: show split positive/negative scores " Dominik Csapak
2025-09-22  8:05 ` Dominik Csapak [this message]
2025-09-22  8:05 ` [pmg-devel] [PATCH pmg-gui 1/1] spam quarantine: add columsn for positive/negative spam score matches Dominik Csapak

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=20250922080509.737332-2-d.csapak@proxmox.com \
    --to=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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal