# <@LICENSE> # Copyright 2006 University of Vienna Computer Center # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # # $Id: ZIDReport.pm 352 2006-07-20 09:37:31Z mrs $ # =head1 NAME ZIDReport - plugin that generates the report used on ZID to transport them to exim =head1 SYNOPSIS loadplugin Mail::SpamAssassin::Plugin::ZIDReport =head1 DESCRIPTION To try this plugin, write the above two lines in the synopsis to C. =cut package ZIDReport; use Mail::SpamAssassin::Plugin; use strict; use warnings; use bytes; use Mail::SpamAssassin::Util; use Mail::SpamAssassin::Logger; use vars qw(@ISA); @ISA = qw(Mail::SpamAssassin::Plugin); # constructor: register the eval rule sub new { my $class = shift; my $mailsaobject = shift; # some boilerplate... $class = ref($class) || $class; my $self = $class->SUPER::new($mailsaobject); bless ($self, $class); # print "registered Mail::SpamAssassin::Plugin::ZIDReport: $self\n"; return $self; } sub check_end { my ($self, $params) = @_; my $pms = $params->{permsgstatus}; my $report = $pms->get_tag("REPORT"); my $version = $pms->get_tag("VERSION"); my $subversion = $pms->get_tag("SUBVERSION"); my $hostname = $pms->get_tag("HOSTNAME"); my $yesno = $pms->get_tag("YESNO"); my $score = $pms->get_tag("SCORE"); my $reqd = $pms->get_tag("REQD"); my $tests = $pms->get_tag("TESTS",","); my $hits = $pms->get_tag("HITS"); my $langs = $pms->get_tag("LANGUAGES"); my $asn = $pms->get_tag("ASN"); my $asncidr = $pms->get_tag("ASNCIDR"); my $relaycountry = $pms->get_tag("RELAYCOUNTRY"); my ($temp, $hdrval, $answer); $temp = "X-Spam-Checker-Version!!SpamAssassin $version ($subversion) on $hostname"; $temp = Mail::SpamAssassin::Util::wrap($temp, "\t", "", 79, 0, '(?<=[\s,])'); $hdrval = (split('!!', $temp, 2))[1]; $hdrval = "" if (! defined $hdrval); $answer = 'version="'.$hdrval.'"'; $temp = "X-Spam-Status!!$yesno, score=$score, required=$reqd, tests=$tests"; $temp = Mail::SpamAssassin::Util::wrap($temp, "\t", "", 79, 0, '(?<=[\s,])'); $hdrval = (split('!!', $temp, 2))[1]; $hdrval = "" if (! defined $hdrval); $answer .= ' status="'.$hdrval.'"'; $temp = "X-Spam-ASN!!$asn $asncidr"; $temp = Mail::SpamAssassin::Util::wrap($temp, "\t", "", 79, 0, '(?<=[\s,])'); $hdrval = (split('!!', $temp, 2))[1]; $hdrval = "" if (! defined $hdrval); $answer .= ' asn="'.$hdrval.'"'; $hdrval = ""; if ((defined $langs) && ($langs ne "")) { $temp = "X-Spam-Languages!!$langs"; $temp = Mail::SpamAssassin::Util::wrap($temp, "\t", "", 79, 0, '(?<=[\s,])'); $hdrval = (split('!!', $temp, 2))[1]; } $hdrval = "" if (! defined $hdrval); $answer .= ' langs="'.$hdrval.'"'; $hdrval = ""; if ((defined $relaycountry) && ($relaycountry ne "")) { $temp = "X-Spam-Relay-Countries!!$relaycountry"; $temp = Mail::SpamAssassin::Util::wrap($temp, "\t", "", 79, 0, '(?<=[\s,])'); $hdrval = (split('!!', $temp, 2))[1]; } $hdrval = "" if (! defined $hdrval); $answer .= ' reltlds="'.$hdrval.'"'; $hdrval = ""; if ((defined $report) && ($report ne "")) { $report =~ s/(?:\r?\n)+$//; # make sure there are no trailing newlines ... $report =~ s/\"/\\"/g; } $report = "" if (! defined $report); $answer .= " report=\"Content analysis details: ($hits points) ".$report.'"'; $pms->set_tag('ZIDREPORT', $answer); 0; } 1;