Alex Kilgore wrote:
Niels Rasmussen wrote:
Alex Kilgore skrev:
I have a mail notifier on my system that I wrote in Perl, The way
that I
managed this was to get the script to write the formatted number of
messages to a file (in this case below it was called "mail") and i had
wmiirc echo the contents (using cat) to the status bar
so my status function in the wmiirc looked something like:
status()
{
echo -n "$(cat '/home/alex/.wmii-3.5/mail')" " $(date
+'%l:%M')"
}
Hi alex
Could you post yor script here please ?
Here you go, Ive commented it to explain a little, you may have to
edit it to your needs, hope this helps
Sorry about the formatting on the previous mail if it didnt show up
right in your mail client,
(In mine the comments word-wrapped all over the place),
if you intend to use the script I would edit out and/or fix those
i made the comment lines a bit shorter (below)
also, in the last block of code, it makes use of alsaplayer, if you
don't use alsa make note of that
I also left all of the paths in there to specific files, you would need
to edit those
#!/usr/bin/perl
#open file
open(STAT,'/home/alex/.wmii-3.5/mail.status');
#get the contents that the file previously had
$mailprev = <STAT>;
#if "No Mail" is written in the file, set the number of messages to 0
if ($mailprev eq "No Mail")
{
$mailprev = 0;
}
#if the file was blank, set the number of messages to 0
if ($mailprev eq "")
{
$mailprev = 0;
}
# The next line fetches the new message count from the POP3 server
#and filter out the irrelevant parts,
#for me, Fetchmail generated the relevant output :
#either "fetchmail: No Mail for ..." or "fetchmail: X messages for...."
#I used fetchmail for this,
#but you could use any other mail checking application,
#of course you would need to alter that
# so that it fits your needs, it would be very easy to use
# whatever you do to check mail, you could do something
# along the lines of
#
# $mail = `ls -al ~/Mail/new |wc -l`."
messages";
#
# to get a message count,
# (I am not too familiar with the maildir format,
# so if I am wrong about that let me know )
$mail = `fetchmail -c | sed -e "s/fetchmail\://" |sed -e "s/for.*//"`;
#open file for writing
open(STAT,'>/home/alex/.wmii-3.5/mail.status');
#actually write the formatted output to the file
print STAT "$mail";
#This whole next section is used to play a sound when new
#mail arrives, omit it if you dont need it
#---------------------------#
#this condition is specific to fetchmail because it generated
#output without 0 in it when there was no mail
if ($mail eq 'No Mail')
{
$mail = 0;
}
$mail =~ /[0-9]/;
if ($mail > $mailprev)
{
system("aplay /home/alex/files/sounds/beep.wav");
stop;
}
#-----------------------------#