#!/usr/bin/perl # -w # A mail filter for X-Mailer header lines. # Phil Hollenback # philiph@pobox.com # 8/10/98 use AnyDBM_File; use Fcntl; # For O_ file creation modes. use Env qw(HOME); # # Configuration Options # # Location of the mailer list database $mailer_db = "/webdocs/html/xmailer/.mailers"; # # End Configuration Options # # Set the program version $version = "1.0"; # Initialize variables. %mailer_hash = (); $found_xmailer = 0; $stamp_date = 0; $today = `date +%m%d%y`; chop $today; if ( not -e "$mailer_db.pag" ) { $stamp_date = 1} # Open the databases. tie %mailer_hash, "AnyDBM_File", $mailer_db, O_RDWR|O_CREAT, 0644 or die "Can't open mailer database file $mailer_db.\n"; # Read the message header and find an X-Mailer entry. Increment the # appropriate mailer_hash entry by one. # Note that only the first X-Mailer entry will be found. while (<>) { # Quit if we reach the end of the header. last if /^$/; if ( /^X-[mM]ailer: (.*)/ ) { $mailer_hash{$1} += 1; $found_xmailer = 1; last; } if ( /^User-Agent: (.*)/ ) { $mailer_hash{$1} += 1; $found_xmailer = 1; last; } if ( /^Message-ID: <(Pine\.\w+\.\d+\.\d+)\..*>/ ) { $mailer_hash{$1} += 1; $found_xmailer = 1; last; } } # If we didn't find an X-Mailer line in the header, increment the # 'unknown' entry by one. if ( $found_xmailer == 0 ) { $mailer_hash{"Unknown Mailer"} += 1; } # Increment the total number of messages received count. Easier to do # it now than suck up the whole database and compute it later. $mailer_hash{"Total Messages Received"} += 1; # Put a date stamp in the database if it's a new database. if ( $stamp_date ) { $mailer_hash{"Date Database Created"} = $today } # Enable these lines for debugging. #foreach $key(sort keys %mailer_hash) # { print STDERR $key, " => ", $mailer_hash{$key}, "\n"; }