A trick with perl

Chris Fortune cfortune at telus.net
Sun Jan 4 01:51:09 CET 2004


Here is a code snippet that may be useful to some of you who are running
custom perl code on a *nix server with bogofilter + other command-line
enabled spam filters.  I needed to feed email to a variety of command-line
programs, but ran into trouble getting them to accept script variables and
output responses back to the script (Open2 didn't work on my system).  The
answer was to create a temporary FIFO file using the mknod command, and feed
it to each program by using file redirection to STDIN, then capture STDOUT
using the `backtick` operator, which works for SpamAssassin, BogoFilter,
ClamAV, and Razor, so far.  Newbies, enjoy!

        # create named block oriented pipe for temporary RAM storage of
email
        # used during SpamAssassin, BogoFilter & ClamAV analyses
        # allows for file < redirection STDIN input and `backtick operator`
STDOUT output
        unless($RAM_file>0 and -e "$RAM_file.FIFO"){
          $RAM_file = rand(1000);
          system "mknod $RAM_file.FIFO b";
        }
        # Loop for each email
            open NP, ">$RAM_file.FIFO" or die $!;
            print NP "$head\n$body\n^D"; # ^D is EOF, just in case
            close NP;
            $response = `bogofilter $options < $RAM_file.FIFO`;
            # do something with $response
            # do other command-line tests
            # compute results
            # do something with email
        # end Loop
        unlink "$RAM_file.FIFO" if -e "$RAM_file.FIFO";

Why am I using a gauntlet of so many spam filters?  Try it and see.  (Hint:
Set each spam filter for the lowest "false positive" configuration....)







More information about the Bogofilter mailing list