Any chance to have the attached patch merged?
It adds _JSONSUMMARY_ report support. Only score and rule is included
to prevent json module dependency (escaping)

Additional (semirelated) change is the removal of a "\n\n" from the report, do
not know why this was included, but I feel it is wrong to enforce?

-- 
Bj(/)rnar
diff --git a/lib/Mail/SpamAssassin/PerMsgStatus.pm 
b/lib/Mail/SpamAssassin/PerMsgStatus.pm
index 8adb5e8..184845f 100644
--- a/lib/Mail/SpamAssassin/PerMsgStatus.pm
+++ b/lib/Mail/SpamAssassin/PerMsgStatus.pm
@@ -250,6 +250,12 @@ BEGIN {
                 $pms->{is_spam} ? 'headers_spam' : 'headers_ham');
     },
 
+    JSONSUMMARY => sub {
+      "[".join(",", map {
+        '{"rule":"'.($_->{rule} || '').'","score":'.$_->{score}.'}'
+      } @{$self->{json_summary_tmp}})."]"
+    },
+
   );
 }
 
@@ -266,6 +272,7 @@ sub new {
     'test_names_hit'    => [ ],
     'subtest_names_hit' => [ ],
     'spamd_result_log_items' => [ ],
+    'json_summary_tmp'  => [ ],
     'tests_already_hit' => { },
     'c'                 => { },
     'tag_data'          => { },
@@ -833,7 +840,7 @@ sub get_report {
 
     $report = $self->_replace_tags($report);
 
-    $report =~ s/\n*$/\n\n/s;
+    $report =~ s/\n*$/\n/s;
     $self->{report} = $report;
   }
 
@@ -2519,6 +2526,12 @@ sub _handle_hit {
               $self->_wrap_desc($desc,
                   3+length($rule)+length($score)+length($area), " " x 28),
               ($self->{test_log_msgs}->{LONG} || ''));
+
+    push(@{$self->{json_summary_tmp}}, {
+        rule  => defined($rule) ? $rule : '',
+        score => defined($score) ? sprintf("%.1f", $score) : 0
+      }
+    );
 }
 
 sub _wrap_desc {

Reply via email to