#!/usr/bin/perl -w
use strict;

my %rejects;
while (my $line = <>) {
    my ($month, $day, $hour, $min, $sec, $msg) = $line =~ /^(\S+)\s(\d+)\s(\d+):(\d+):(\d+)\s\S+\s\S+\s(.*)$/;
    $msg =~ s/^[A-F0-9]+: //;
    next unless $msg;

    if ($msg =~ /^reject: .*?; from=.*?: (.*)$/) {
        $rejects{$1}++;
    }
}

my $total = 0;
for my $rej (sort {$rejects{$a} <=> $rejects{$b}} keys %rejects) {
    print $rejects{$rej}."\t$rej\n";
    $total += $rejects{$rej};
}
print "$total\tTotal rejected mails\n";
