You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by km...@apache.org on 2019/06/07 15:09:53 UTC
svn commit: r1860766 - in /spamassassin:
branches/3.4/lib/Mail/SpamAssassin/PerMsgStatus.pm
trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
Author: kmcgrail
Date: Fri Jun 7 15:09:53 2019
New Revision: 1860766
URL: http://svn.apache.org/viewvc?rev=1860766&view=rev
Log:
Improving Debug output for subtest rule hits
Modified:
spamassassin/branches/3.4/lib/Mail/SpamAssassin/PerMsgStatus.pm
spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
Modified: spamassassin/branches/3.4/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.4/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=1860766&r1=1860765&r2=1860766&view=diff
==============================================================================
--- spamassassin/branches/3.4/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/branches/3.4/lib/Mail/SpamAssassin/PerMsgStatus.pm Fri Jun 7 15:09:53 2019
@@ -398,7 +398,7 @@ sub check_timed {
dbg("check: is spam? score=".$self->{score}.
" required=".$self->{conf}->{required_score});
dbg("check: tests=".$self->get_names_of_tests_hit());
- dbg("check: subtests=".$self->get_names_of_subtests_hit());
+ dbg("check: subtests=".$self->get_names_of_subtests_hit("dbg"));
$self->{is_spam} = $self->is_spam();
$self->{main}->{resolver}->bgabort();
@@ -764,12 +764,52 @@ meta-rule sub-tests which were triggered
normally-hidden rules, which score 0 and have names beginning with two
underscores, used in meta rules.
+If a parameter of dbg is passed, the output will be more condensed and
+sub-tests with multiple hits reduced to one entry with the number of hits
+in parentheses. Some information is also added at the end regarding the
+multiple hits.
+
=cut
sub get_names_of_subtests_hit {
- my ($self) = @_;
+ my ($self, $mode) = @_;
- return join(',', sort @{$self->{subtest_names_hit}});
+ if (defined $mode && $mode eq 'dbg') {
+ #This routine prints only one instance of a subrule hit with a count of how many times it hit if greater than 1
+ my (%subtest_names_hit, $i, $key, @keys, @sorted, $string, $rule, $total_hits, $deduplicated_hits);
+
+ $total_hits = scalar(@{$self->{subtest_names_hit}});
+
+ for ($i=0; $i < $total_hits; $i++) {
+ $rule = ${$self->{subtest_names_hit}}[$i];
+ $subtest_names_hit{$rule}++;
+ }
+
+ foreach $key (keys %subtest_names_hit) {
+ push (@keys, $key);
+ }
+ @sorted = sort @keys;
+
+ $deduplicated_hits = scalar(@sorted);
+
+ for ($i=0; $i < $deduplicated_hits; $i++) {
+ $string .= $sorted[$i];
+ if ($subtest_names_hit{$sorted[$i]} > 1) {
+ $string .= "($subtest_names_hit{$sorted[$i]})"
+ }
+ $string .= ",";
+ }
+
+ $string =~ s/,$//;
+
+ $string .= " (Total Subtest Hits: $total_hits / Deduplicated Total Hits: $deduplicated_hits)";
+
+ return $string;
+
+ } else {
+ #return the simpler string with duplicates and commas
+ return join(',', sort @{$self->{subtest_names_hit}});
+ }
}
###########################################################################
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=1860766&r1=1860765&r2=1860766&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Fri Jun 7 15:09:53 2019
@@ -407,7 +407,7 @@ sub check_timed {
dbg("check: is spam? score=".$self->{score}.
" required=".$self->{conf}->{required_score});
dbg("check: tests=".$self->get_names_of_tests_hit());
- dbg("check: subtests=".$self->get_names_of_subtests_hit());
+ dbg("check: subtests=".$self->get_names_of_subtests_hit("dbg"));
$self->{is_spam} = $self->is_spam();
$self->{main}->{resolver}->bgabort();
@@ -773,12 +773,52 @@ meta-rule sub-tests which were triggered
normally-hidden rules, which score 0 and have names beginning with two
underscores, used in meta rules.
+If a parameter of dbg is passed, the output will be more condensed and
+sub-tests with multiple hits reduced to one entry with the number of hits
+in parentheses. Some information is also added at the end regarding the
+multiple hits.
+
=cut
sub get_names_of_subtests_hit {
- my ($self) = @_;
+ my ($self, $mode) = @_;
- return join(',', sort @{$self->{subtest_names_hit}});
+ if (defined $mode && $mode eq 'dbg') {
+ #This routine prints only one instance of a subrule hit with a count of how many times it hit if greater than 1
+ my (%subtest_names_hit, $i, $key, @keys, @sorted, $string, $rule, $total_hits, $deduplicated_hits);
+
+ $total_hits = scalar(@{$self->{subtest_names_hit}});
+
+ for ($i=0; $i < $total_hits; $i++) {
+ $rule = ${$self->{subtest_names_hit}}[$i];
+ $subtest_names_hit{$rule}++;
+ }
+
+ foreach $key (keys %subtest_names_hit) {
+ push (@keys, $key);
+ }
+ @sorted = sort @keys;
+
+ $deduplicated_hits = scalar(@sorted);
+
+ for ($i=0; $i < $deduplicated_hits; $i++) {
+ $string .= $sorted[$i];
+ if ($subtest_names_hit{$sorted[$i]} > 1) {
+ $string .= "($subtest_names_hit{$sorted[$i]})"
+ }
+ $string .= ",";
+ }
+
+ $string =~ s/,$//;
+
+ $string .= " (Total Subtest Hits: $total_hits / Deduplicated Total Hits: $deduplicated_hits)";
+
+ return $string;
+
+ } else {
+ #return the simpler string with duplicates and commas
+ return join(',', sort @{$self->{subtest_names_hit}});
+ }
}
###########################################################################