tom(_at_)Mail(_dot_)Coast(_dot_)NET (Engineer on Caffeine) writes:
Got a question that I think it a simple one. Like just about everybody
the reason I started running procmail was to filter the hundereds of
pieces of mail I get in a day, but one thing I have noticed is that I now
have no way of know that there is new mail in a box. Is there a script or
another method that can notify me of new mail, without print a large
amount of stuff to the screen?
Well, You can play with the following perl5 script if you like.
You'll have to tweak it a bit to make it work in your enviornment:
(you can then use xlbiff to look at the log file:
/usr/pkg/contrib/bin/xlbiff -file /home/hardaker/Mail/MAIL_LOG -scanCommand
"/usr/local/bin/perl5 /home/hardaker/bin/scripts/mlog2list"
By default, it only scans the last 15 entries unless you put more on
the command line. This script is VERY taylored to my environment. It
will NOT work out of the box for you. You will probably HAVE to know
perl(5) to get it working.
wheeeee.
Wes
#!/usr/local/bin/perl5
LOGFILE="/home/hardaker/Mail/MAIL_LOG";
$max = 15;
$c = 0;
$_ = localtime(time());
($today,$mon,$day) = /^(\w+) (\w+) (\d+)/;
if ($#ARGV == 0) {
$max = $ARGV[0];
}
open(LOG,$LOGFILE);
while (<LOG>) {
next if ($_ !~ /^From: +(.*)/);
if (/^From:.*\((.*)\)/) {
$from = $1;
} elsif (/^From:.*\"(.*)\"/) {
$from = $1;
} elsif (/^From: +(.*)</) {
$from = $1;
} elsif (/^From: +(.*)From/) {
$from = $1;
} else {
$from = "Unknown";
}
if (/$today +$mon +$day +(\d+):(\d+):\d+/) {
$date = "$1:$2";
}
elsif (/(\w+) +\w+ +\d+ +\d+:\d+:\d+/) {
$date = " $1 ";
} else {
$date = "?????";
}
# next if ($_ !~ /^From ([\w-]+)/);
last if (!($_ = <LOG>));
next if ($_ !~ /^\s*Subject:(.*)/);
$subject = $1;
last if (!($_ = <LOG>));
if ($_ =~ /^\s*Folder: \/usr\/pkg\/mh\/bin\/rcvstore \+([\w\/]+)/) {
$_ = $1;
} elsif ($_ =~ /^\s*Folder:
\/home\/hardaker\/News\/spool\/([\w\.-]+)\.spool/) {
$_ = $1;
s/netbsd\.//;
} else {
next;
}
s/.*\///;
$folder = $_;
shift @list if ($c > $max);
push(@list,[$from,$subject,$folder,$date]);
$c = $c + 1;
}
for($i = 0; $i <= $#list; $i++) {
printf("%-5.5s %-10.10s %-14.14s %-45.45s\n",$list[$i]->[3],
$list[$i]->[2], $list[$i]->[0], $list[$i]->[1]);
}