#!/usr/athena/bin/perl

%mname = ("Jan", 1,
	  "Feb", 2,
	  "Mar", 3,
	  "Apr", 4,
	  "May", 5,
	  "Jun", 6,
	  "Jul", 7,
	  "Aug", 8,
	  "Sep", 9,
	  "Oct", 10,
	  "Nov", 11,
	  "Dec", 12);

@days = (0,0,31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365);

@log = `tail -100 /afs/sipb/project/www/queue/lock-log`;
$qsize = `ls /afs/sipb/project/www/queue/Mail/inbox | wc -l`;
$qsize=~s/\s//g;
foreach (@log){
    split;
    $ct++;
    if($_[5]=~/199/){
	$offset=1;
    }
    else{
	$offset=0;
    }

    $who = $_[5+$offset];
    $what = $_[7+$offset];
    $month = $_[1];
    $mon = $mname{$month};
    $day = $_[2];
    $time = $_[3];
    $year = $_[4+$offset];
    $maildate = $_[8+$offset];
    $sender = $_[9+$offset];
    ($mailmon, $mailday) = split("/", $maildate);
    next if $what !~/locked/;
    next if !int($mailday);
    $buster{$who}++;
    $replied = ($days[$mon])+$day;
    $when{$replied}++;
}
$repliedlast = ($days[$mon])+$day;

$rate = int(100/($repliedlast-$repliedfirst));
$since = ($repliedlast-$repliedfirst);
print("Messages answered...\n");
print "\tToday: $when{$repliedlast}\n";
print "\tYesterday: $when{$repliedlast-1}\n";
print "\tDay Before: $when{$repliedlast-2}\n";
print("There are currently $qsize messages in the queue.\n");
print("Top recent queuebusters:\n");
foreach $qb (sort {$buster{$b} <=> $buster{$a};} keys %buster){
    print "\t$qb: $buster{$qb}\n";
}
