Email count as per sender

Step: 01
vi /root/totalmail.pl

#!/usr/bin/perl#
# usage: totalEmail.pl
# summary: count the number of recipients that each accounts has sent email to
#

%sender_list = (); #ip list

chdir "/var/log";
for (glob 'zimbra.log*')
#for (glob 'zimbra.log')
{

# audit.log is always todays stuff
#print "***** Opening file $_","\n";
if ($_ eq 'zimbra.log')
{
$audit_log = 1;
open (IN, sprintf("cat %s |", $_))
or die("Can't open pipe from command 'zcat $filename' : $!\n");
}
else
{
$audit_log = 0;
open (IN, sprintf("zcat %s |", $_))
or die("Can't open pipe from command 'zcat $filename' : $!\n");
}

while (<IN>)
{
if (m#RelayedOutbound#)
{
my $recipcnt = 0;

next if (m#dkim_s#); # messasges are listed twice (first via clamav then dkim signed)

($sender, $recipients) = m#[^<]+<([^>]+)>[^<]+(.*)\s+Queue-ID#;
$recipcnt = $recipients =~ tr/,/,/;
$sender_list{$sender} += $recipcnt; # count number or recipients

#print "sender $sender, recipients $recipients count: $sender_list{$sender}\n";
}
}
close (IN);
}

# print out totals per sender
printSenders();

sub printSenders
{
my $sender = ();

for $sender (sort {$sender_list{$b} <=> $sender_list{$a}} keys %sender_list)
{
print "$sender sent: $sender_list{$sender}\n";
}
}


Step: 02
chmod +x /root/totalmail.pl


Step: 03
/root/totalmail.pl

Comments

Popular posts from this blog

Cambium cnPilot E400/E410/E500 Configuration Tutorial

Disabling Zimbra's AntiSpam, Amavis and AntiVirus filtering

Error "Unable to retrive Zimbra GPG key for package validation"