]> git.donarmstrong.com Git - spamassassin_config.git/blob - bugs/clamav.pm
add a clamav scanner to the BTS SA configuration
[spamassassin_config.git] / bugs / clamav.pm
1 # This provides a spamassassin clamav plugin and
2 # is released under the terms of the GPL version 3, or any later
3 # version (at your option). See the file README and COPYING for more
4 # information.
5 # Copyright 2017 by Don Armstrong <don@donarmstrong.com>.
6
7 package clamav;
8
9 =head1 NAME
10
11 clamav -- Clamav scanner
12
13 =head1 SYNOPSIS
14
15 Plugin for spamssassin which checks mail using clamav
16
17 =head1 DESCRIPTION
18
19
20 =head1 BUGS
21
22 None known.
23
24 =cut
25
26
27 use warnings;
28 use strict;
29
30 use ClamAV::Client;
31
32 use Mail::SpamAssassin;
33 use base qw(Mail::SpamAssassin::Plugin);
34
35 sub new {
36     my ($class,@opts) = @_;
37     $class = ref($class) // $class;
38     my $self = $class->SUPER::new(@opts);
39     bless($self,$class);
40     $self->register_eval_rule("check_clamav");
41     return $self;
42 }
43
44 sub check_clamav {
45     my ($self,$pms,$fulltext) = @_;
46
47     my $scanner = ClamAV::Client->new();
48     if (not defined $scanner) {
49         dbg("ClamAv is not running or could not connect to it");
50         return 0;
51     }
52     my $ret = 0;
53     my $infected = $scanner->scan_scalar(\$fulltext);
54     if (defined $infected) {
55         $ret = 1;
56         $pms->set_tag('CHECKCLAMAV','Yes '.$infected);
57         $pms->get_message->put_metadata('X-Spam-Virus','Yes '.$infected);
58     } else {
59         $pms->set_tag('CHECKCLAMAV','No');
60         $pms->get_message->put_metadata('X-Spam-Virus','No');
61     }
62     return $ret;
63 }
64
65
66
67 1;
68
69
70 __END__