#!/usr/bin/perl
# dale@bewley.net 05/28/98, 06/19/98
# count number of mails from each incoming address in procmail.log
# Example interesting line from promail.log looks like this:
#From trever@monster.com  Mon Aug 30 14:52:56 1999


$ARGV[0] || die "Usage: $0 <~/mail/procmail.log>\n";
while (<>) {
	# skip lines not beginning with "From"
        $_ !~ /^From/ && next; 
	# add email address to hash and increment count of occurances
	# the email address is the second word on the line
	$count{(split())[1]}++ 
}
foreach $address (
	sort { $count{$b} <=> $count{$a} or lc $a cmp lc $b } keys %count) {

        #print "$count{$address} $address\n"
        write;
}

foreach (values %count) {
	$total += $_;
}

print "\nTotal\n------\n$total\n";

format top =
Count   From Email Address
------ -----------------------------------------------------------------------
.
format STDOUT =
@>>>>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$count{$address}, $address
.

