# # Courier::Filter::Module::ClamAV class # # Michael Carmack # ############################################################################## =head1 NAME Courier::Filter::Module::ClamAV - A ClamAV filter module for the Courier::Filter framework =cut package Courier::Filter::Module::ClamAV; =head1 VERSION 0.12 =cut our $VERSION = 0.12; =head1 SYNOPSIS use Courier::Filter::Module::ClamAV; my $module = Courier::Filter::Module::ClamAV->new( logger => $logger, inverse => 0, trusting => 0, testing => 0, debugging => 0 ); my $filter = Courier::Filter->new( ... modules => [ $module ], ... ); =cut use warnings; #use diagnostics; use strict; use base qw(Courier::Filter::Module); use Mail::ClamAV 0.11 qw/:all/; # Constants: ############################################################################## use constant TRUE => (0 == 0); use constant FALSE => not TRUE; use constant DEFAULT_MAXRECLEVEL => 4; use constant DEFAULT_MAXFILES => 20; use constant DEFAULT_MAXFILESIZE => 1024 * 1024 * 10; # Interface: ############################################################################## =head1 DESCRIPTION This class is a filter module class for use with Courier::Filter. It detects viruses. =cut sub new; sub match; # Implementation: ############################################################################## =head2 Constructor The following constructor is provided: =over =item B: RETURNS Courier::Filter::Module::ClamAV Creates a new B filter module. %options is a list of key/value pairs representing any of the following options: =over =item B Maximum recursion level. Defaults to B<4>. =item B Maximum files to scan. Defaults to B<20>. =item B Maximum file size to scan. Defaults to B<10MB>. =back All options of the B constructor are also supported. Please see L for their descriptions. =cut sub new { my ($class, %options) = @_; $options{maxreclevel} ||= DEFAULT_MAXRECLEVEL; $options{maxfiles} ||= DEFAULT_MAXFILES; $options{maxfilesize} ||= DEFAULT_MAXFILESIZE; my $clam; return $class->SUPER::new(%options, clam => $clam); } =back =head2 Instance methods See L for a description of the provided instance methods. =cut # Note: Possible Mail::ClamAV status outputs: # errno - The numeric value (if any) clamav returned. # clean - True if the message was not a virus and no error occured. # virus - True if the message is a virus. # error - The error message (if any). Equivalent to quoting "${status}" # count - Number of messages scanned (archives only) sub match { my ($module, $message) = @_; my $class = ref($module); my $clam = $module->{clam}; # If object is uninitialized, or if virus definitions have changed, init. if (!$clam || $clam->statchkdir()) { $clam = Mail::ClamAV->new(Mail::ClamAV::retdbdir()); $clam->buildtrie; $clam->maxreclevel($module->{maxreclevel}); $clam->maxfiles($module->{maxfiles}); $clam->maxfilesize($module->{maxfilesize}); $module->{clam} = $clam; } my $status = $clam->scan($message->file_name,CL_ARCHIVE|CL_MAIL); if ( $status->virus ) { return "Virus Detected: $status"; } return undef; } =head1 SEE ALSO L, L, L. For AVAILABILITY, SUPPORT, COPYRIGHT, and LICENSE information, see L. =head1 REFERENCES =over =item B L =back =head1 AUTHOR Michael Carmack =cut TRUE;