i use gnu screen as my "primary" window manager, layered on top of xmonad which places me in a X environment that is as close to being in the console as possible.
while using screen, i like to see when i have new email at my imap account.
to do this i have written a perl script that checks my imap account and dumps the results to STDOUT, which i can redirect to a file. that file can be cat'd and displayed in the screen status bar.
the following code uses the perl package
Net::IMAP::Simple::SSL
which can be obtained in debian using the command:
apt-get install libnet-imap-simple-ssl-perl
in freebsd, the port for this is:
mail/p5-Net-IMAP-Simple-SSL
here is the code - fill in your own imap provider and authentication.
#!/usr/bin/perl -w
use strict;
use Net::IMAP::Simple::SSL;
my $server = '';
my $user = '';
my $pass = '';
my $imap = Net::IMAP::Simple::SSL->new($server);
$imap->login($user => $pass) || die "cannot connect";
my $messages = $imap->select('INBOX');
my $count = 0;
for my $msg (1..$messages) {
$count++ unless $imap->seen($msg);
}
$imap->quit();
if ($count == 1) {
print "1 NEW MAIL";
}
if ($count > 1) {
print "$count NEW MAILS";
}
we can automate this (assuming you replace $PATH with a valid path) in cron with a command like:
$PATH/imapbiff.pl > /tmp/.newmail
and then in our .screenrc, use something like:
backtick 1 120 120 $PATH/showmail.sh
hardstatus alwayslastline "%{= kw}%?%-Lw%?%{= kw}%n*%f %t%?(%u)%?%{= kw}%?%+Lw%?%{= kw} %=%1` %c %m/%d/%Y"
where showmail.sh simply cats the /tmp/.newmail file.
it is important to note that you do not want to put the call to imapbiff.pl directly in your .screenrc. if you do, each new screen window you open will be delayed while this command is executed. by only cat'ting the status file in .screenrc, you will only have to wait for this very fast cat operation to complete in order to get an interactive prompt.
last update 11/30/2007