Hi all,
I was looking for a mail.log filter to monitor incoming and outgoing
mail in a transparent Eterm. I didn't find anything out there that
made the mail.log file more humanly readable, so I wrote my own in
perl. I'm including it below. It works in debian. You may have to
edit the $maillog variable to point to the mail log on other Linux
variants. I also had to change the line 'adm:x:4:' to 'adm:x:4:rob'
in /etc/group to be able to read the mail.log file.
The output looks something like this:
Dec 14 09:17:15 From: <[EMAIL PROTECTED]>
Dec 14 10:04:36 From: <[EMAIL PROTECTED]>
Dec 14 10:08:43 To: [EMAIL PROTECTED] Status: Message accepted for delivery
Dec 14 10:08:43 From: <[EMAIL PROTECTED]>
-Rob.
#!/usr/bin/perl
#
# Reads a mail log and prints a human readable output of
# incoming and outgoing mails.
#
# Created 20001213 by Rob Hudson
use IO::File;
my $maillog = "/var/log/mail.log";
my $sleeptime = 5;
open (ML, $maillog) or die "Can't open $maillog: $!";
seek (ML, -10240, SEEK_END);
for (;;) {
while (<ML>) {
if (/procmail/) { next; }
my $date = substr ($_, 0, 15);
if ($_ =~ /from=(<.*?>)/) {
print "$date From: $1\n";
}
if ($_ =~ /to=(.*?),\sctl/) {
print "$date To: $1";
if ($_ =~ /Sent \([A-Za-z0-9]* ([A-Za-z ]*?)\)$/) {
print " Status: $1\n";
} else {
print "\n";
}
}
#print $_;
}
sleep $sleeptime;
ML->clearerr();
}