1# GrepRenderedBody - dump SpamAssassin memory structures to disk after each message 2# 3# use as follows: 4# 5# ./mass-check --cf='loadplugin GrepRenderedBody plugins/GrepRenderedBody.pm' \ 6# --cf='grep REGEXP' \ 7# [normal mass-check arguments] 8# 9# e.g. 10# 11# ./mass-check --cf='loadplugin GrepRenderedBody plugins/GrepRenderedBody.pm' \ 12# --cf='grep This is a test\.' \ 13# --net -n -o spam:dir:/local/cor/recent/spam/high.2007010* 14 15package GrepRenderedBody; 16use strict; 17use Mail::SpamAssassin; 18use Mail::SpamAssassin::Plugin; 19our @ISA = qw(Mail::SpamAssassin::Plugin); 20 21sub new { 22 my ($class, $mailsa) = @_; 23 $class = ref($class) || $class; 24 my $self = $class->SUPER::new($mailsa); 25 warn "GrepRenderedBody plugin loaded"; 26 27 $mailsa->{conf}->{parser}->register_commands([{ 28 setting => 'grep', 29 type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 30 }]); 31 32 $self->{conf} = $mailsa->{conf}; 33 34 bless ($self, $class); 35 return $self; 36} 37 38sub mass_check_skip_message { 39 my ($self, $opts) = @_; 40 my $ary = $opts->{msg}->get_rendered_body_text_array(); 41 my $re = $self->{conf}->{grep}; 42 43 # no RE? allow all msgs 44 if (!defined $re) { return 0; } 45 46 foreach my $l (@{$ary}) { if ($l =~ /${re}/s) { return 0; } } 47 return 1; 48} 49 501; 51