26.19 Viruses

REVIEW

clamav, clamav, clamav, clamav clamav-freshclam, clamav-freshclam

The clamav, clamav, clamav, clamav package can be used to check email for viruses. The virus data will be updated automatically if clamav-freshclam, clamav-freshclam is installed.

The clamscan command can also be used used with procmail by using a script (in this case, clamfilter.pl from http://www.everysoft.com/) to run clamscan on each message with a procmail entry like:

  :0fw
  | clamfilter.pl
  :0:
  * ^X-Virus-Found: yes
  clam-`date +%Y-%m`

The actual script to add the appropriate X-Virus-Found header is:

#!/usr/bin/perl -w
#
# ClamFilter 1.0
# by Matt Hahnfeld (http://www.everysoft.com/)
# Requires perl, clamscan, procmail, and this script. 
#
# Add these lines to your .procmailrc:
#
# :0fw
# | /usr/local/bin/clamfilter.pl
# 
# This script is public domain. 
#

use strict;
use File::Temp 'tempfile';

&main();
exit 0;

sub main {
  # Set up a temporary file for the original message
  my ($tmpfh, $tmpfn) = tempfile( UNLINK => 1 );
  -w $tmpfn or die 'Could not open temp file!';

  # Pass 1: Write out the temporary file
  while (<STDIN>) {
    print $tmpfh $_;
  }
  seek($tmpfh, 0, 0);

  # Pass 2: Scan the message
  open CLAMSCAN, "/bin/cat $tmpfn | /usr/bin/clamscan --stdout --recursive --mbox - 2>/dev/null |" or die 'Could not open clamscan!';
  my $clamstatus = qq|X-Virus-Found: yes
X-Virus-Status:
 ------------------------------------------------------------
 Virus Scan Status:
 ------------------------------------------------------------
|;
  while (<CLAMSCAN>) {
    $clamstatus .= ' ' . $_;
  }
  close CLAMSCAN;
  $clamstatus .= qq| 
 ------------------------------------------------------------

|;

  # Pass 3: Print out the message
  my $bodyflag = 0;
  while (<$tmpfh>) {
    if (! $bodyflag and $_ eq "\n") {
      if ($?) {
        print $clamstatus;
      }
      else {
        print "\n";
      }
      $bodyflag = 1;
    }
    else {
      print;
    }
  }
}


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0