On 4/24/2014 11:04 AM, David F. Skoll wrote:
We integrate with SpamAssassin at the Perl library level, and we reach
into the innards to get at the test scores.  Here's our code:

        my $conf = $sa_status->{conf} || {};
        my $scores = $conf->{scores} || {};
        my $testnames = join(',', (map { (exists($scores->{$_}) && defined($scores->{$_})) ? $_ 
. ':' . $scores->{$_} : "$_:?" } (split(/\s*,\s*/, $sa_status->get_names_of_tests_hit()))));

We end up getting output like this in our logs:

HTML_IMAGE_ONLY_20:0.7;HTML_MESSAGE:0.001;MIME_HTML_ONLY:1.105;RDNS_NONE:1.274;TO_EQ_FM_DOM_HTML_ONLY:0.489;TO_EQ_FM_HTML_ONLY:0.036;TO_NO_BRKTS_NORDNS:0.001;T_REMOTE_IMAGE:0.01

Could we make an official API call something like this?
Keeping more in the like and kind with the existing code in PMS, wouldn't this be closer to what you need? Completely untested but passed tests.

I debated making the routine get_names_of_tests_hit_with_scores call get_names_of_tests_hit_with_scores to unify things a small bit but then I would need to convert to an array and sort. Alternately, perhaps I could use wantarray and combine the two functions.

Once this is done, it lays the groundwork to put get_names_of_tests_hit_with_scores into spamd.

Index: lib/Mail/SpamAssassin/PerMsgStatus.pm
===================================================================
--- lib/Mail/SpamAssassin/PerMsgStatus.pm       (revision 1587672)
+++ lib/Mail/SpamAssassin/PerMsgStatus.pm       (working copy)
@@ -727,6 +727,55 @@
   return join(',', sort(@{$self->{test_names_hit}}));
 }

+=item $list = $status->get_names_of_tests_hit_with_scores_hash ()
+
+After a mail message has been checked, this method can be called. It will
+return a pointer to a hash for rule & score pairs for all the symbolic
+test names and individual scores of the tests which were trigged by the mail.
+
+=cut
+sub get_names_of_tests_hit_with_scores_hash {
+  my ($self) = @_;
+
+  my ($line, %testsscores);
+
+  #BASED ON CODE FOR TESTSSCORES TAG - KAM 2014-04-24
+  foreach my $test (@{$self->{test_names_hit}}) {
+    my $score = $self->{conf}->{scores}->{$test};
+    $score = '0'  if !defined $score;
+
+    $testsscores{$test} = $score;
+  }
+
+  return \%testsscores;
+}
+
+=item $list = $status->get_names_of_tests_hit_with_scores ()
+
+After a mail message has been checked, this method can be called. It will
+return a comma-separated string of rule=score pairs for all the symbolic
+test names and individual scores of the tests which were trigged by the mail.
+
+=cut
+sub get_names_of_tests_hit_with_scores {
+  my ($self) = @_;
+
+  my ($line, %testsscores);
+
+  #BASED ON CODE FOR TESTSSCORES TAG - KAM 2014-04-24
+  foreach my $test (sort @{$self->{test_names_hit}}) {
+    my $score = $self->{conf}->{scores}->{$test};
+    $score = '0'  if !defined $score;
+    $line .= ','  if $line ne '';
+    $line .= $test . '=' . $score;
+  }
+
+  $line ||= 'none';
+
+  return $line;
+}
+
+
 ###########################################################################

Regards,
KAM

Reply via email to