[pmg-devel] [PATCH pmg-api 1/2] statistics: spamscores: fix total count when there is outgoing spam

Dominik Csapak d.csapak at proxmox.com
Mon Mar 27 16:53:54 CEST 2023


We used 'count_in' as total value, but the spamlevel counts also
counted outgoing mails, so we could have weird stats with negative
mails.

To fix that, we simply count all mails, incoming and outgoing.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PMG/API2/Statistics.pm | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/PMG/API2/Statistics.pm b/src/PMG/API2/Statistics.pm
index 38c8d0c..051265b 100644
--- a/src/PMG/API2/Statistics.pm
+++ b/src/PMG/API2/Statistics.pm
@@ -1057,7 +1057,7 @@ __PACKAGE__->register_method ({
 
 	my $res = [];
 
-	my $count_in = $totalstat->{count_in};
+	my $total = $totalstat->{count_in} + $totalstat->{count_out};
 
 	my $levelcount = {};
 	my $spamcount = 0;
@@ -1070,11 +1070,11 @@ __PACKAGE__->register_method ({
 	    }
 	}
 
-	$levelcount->{0} = $count_in - $spamcount;
+	$levelcount->{0} = $total - $spamcount;
 
 	for (my $i = 0; $i <= 10; $i++) {
 	    my $count = $levelcount->{$i} // 0;
-	    my $ratio = $count_in ? $count/$count_in : 0;
+	    my $ratio = $total ? $count/$total : 0;
 	    push @$res, { level => $i, count => $count, ratio => $ratio };
 	}
 
-- 
2.30.2





More information about the pmg-devel mailing list