[pmg-devel] [PATCH pmg-api 1/1] api: quarantine: include positive and negative spam score sum in list

Dominik Csapak d.csapak at proxmox.com
Mon Sep 22 10:05:00 CEST 2025


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 at 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





More information about the pmg-devel mailing list