#!/usr/bin/perl use Tk; use Mail::IMAPClient; ################################################################################ $mediumfont = "-adobe-times-medium-r-normal-*-*-100-*-*-p-*-iso8859-1"; $boldfont = "-adobe-times-bold-r-normal-*-*-100-*-*-p-*-iso8859-1"; $geometry = "+0+0"; $interval = 60000; $limit = 5; $bell = 1; $server = ""; $username = ""; $password = ""; $mailbox = "INBOX"; ################################################################################ $mainwindow = MainWindow->new; $mainwindow->title("spliff v0.1"); $mainwindow->geometry($geometry); $mainwindow->resizable(0, 0); $topframe = $mainwindow->Frame(-relief => 'raised', -borderwidth => 1)->pack(); $topframe->Label(-text => "From", -font => $boldfont, -width => 15, -padx => 5, -pady => 0, -anchor => 'w')->pack(-side => 'left'); $topframe->Label(-text => "Subject", -font => $boldfont, -width => 25, -padx => 5, -pady => 0, -anchor => 'w')->pack(-side => 'left'); $topframe->Label(-text => "Date", -font => $boldfont, -width => 20, -padx => 5, -pady => 0, -anchor => 'w')->pack(-side => 'left'); $middleframe = $mainwindow->Frame()->pack(); for ($loop = $limit; $loop > 0; $loop--) { $middleframe->Label(-textvariable => \$from[$loop], -font => $mediumfont, -width => 15, -padx => 5, -pady => 0, -anchor => 'w')->grid($middleframe->Label(-textvariable => \$subject[$loop], -font => $mediumfont, -width => 25, -padx => 5, -pady => 0, -anchor => 'w'), $middleframe->Label(-textvariable => \$date[$loop], -font => $mediumfont, -width => 20, -padx => 5, -pady => 0, -anchor => 'w')); } $bottomframe = $mainwindow->Frame(-relief => 'raised', -borderwidth => 1)->pack(-fill => 'x'); $bottomframe->Label(-textvariable => \$status, -font => $mediumfont, -pady => 0)->pack(); $status = "Connecting to $server IMAP as $username..."; $mainwindow->after(1000, \&update); $mainwindow->repeat($interval, \&update); MainLoop; sub update { $imap = Mail::IMAPClient->new(Server => $server, User => $username, Password => $password); if (!$imap) { $status = "Unable to connect to $server IMAP"; return; } $count = $imap->message_count($mailbox); if ($count < 1) { $status = "There are no messages in $mailbox"; } else { $status = "Most recent $limit of $count messages in $mailbox"; } $last = $count - $limit; $last = 0 if ($count < $limit); for ($loop = $count; $loop > $last; $loop--) { $imap->examine($mailbox); $info = $imap->parse_headers($loop, "From", "Subject", "Date"); $message = $loop - $last; $from[$message] = $info->{From}[0]; $from[$message] =~ s/(.*) <.*/$1/; $from[$message] =~ s/^\"(.*)\"$/$1/; $subject[$message] = $info->{Subject}[0]; $date[$message] = $info->{Date}[0]; $date[$message] =~ s/\w{3}, (.*\d{4} \d{2}:\d{2}:\d{2}) \-\d{4}/$1/; } $imap->disconnect; $mainwindow->bell() if ($bell == 1 && $count > $oldcount && $passed == 1); $oldcount = $count; $passed = 1; }