Mail/Qmail/Filter/ClamAV.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 62 CC 5 SCAR 27.7
CC
5
Cov
0%
filter
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 16.0
1 use 5.014;
2 use warnings;
3  
4 package Mail::Qmail::Filter::ClamAV;
5  
6 our $VERSION = '1.0';
7  
8 use Mo qw(coerce default);
9 extends 'Mail::Qmail::Filter';
10  
11 has 'clamav_options' => sub { [] };
12 has 'dump_malware_to';
13 has 'error_text' => 'An error occured when scanning the message for viruses.';
14 has 'reject_text' => sub {
15 sub { "Virus found: $_[0]" }
16 };
17  
18 sub filter {
19 my $self = shift;
20 my $message = $self->message;
21 my $body_ref = $message->body_ref;
22  
23 require File::Scan::ClamAV; # lazy load because filter might be skipped
24 my $av = File::Scan::ClamAV->new( @{ $self->clamav_options } );
25 my ( $response, $virus ) = $av->streamscan($$body_ref);
26 if ( my $errstr = $av->errstr ) {
27 $self->defer( $self->error_text, $errstr );
28 }
29 else {
30 $self->debug( result => $response );
31 if ($virus) {
32 $self->debug( virus => $virus );
33 if ( defined( my $dir = $self->dump_malware_to ) ) {
34 require Path::Tiny and Path::Tiny->import('path')
35 unless defined &path;
36 path( $dir, my $file = join '_', $^T, $$, $virus =~ y!/\n!_!r )
37 ->spew($$body_ref);
38 $self->debug( 'dumped message to' => $file );
39 }
40 $self->reject( $self->reject_text, $virus );
41 }
42 }
43 }
44  
45 1;
46  
47 __END__