My work email tends to accumulate a lot of cruft, even after filtering away the noise that can be recognised automatically with regexes, so I wrote this script (used as a conky plugin) which polls my IMAP mailbox & returns the sender & subject of unread messages, suitably trimmed. Then I can see at a glance whether any need attention.
#!/usr/bin/perl #===================================================================== +========== # # FILE: unread_email.pl # # USAGE: ./unread_email.pl # # DESCRIPTION: Check for unread IMAP email, return sender & subject # # OPTIONS: none # REQUIREMENTS: Mail::IMAPTalk # BUGS: Only checks INBOX # NOTES: --- # AUTHOR: (Stephen Patterson), <steve@patter.mine.nu> # COMPANY: # VERSION: 1.0 # CREATED: 23/01/08 10:50:37 GMT # REVISION: --- #===================================================================== +========== use strict; use warnings; my $username = 'imap user'; my $password = 'imap password'; my $server = 'imap server'; use Mail::IMAPTalk; sub find_messages { my $IMAP = Mail::IMAPTalk->new( Server => $server, Username => $username, Password => $password, Uid => 1 ) or die "Couldn't connect"; $IMAP->select('inbox'); my @MsgIds = $IMAP->search('not', 'seen'); my @messages; foreach my $uid (@MsgIds) { my %info = fetch_message($IMAP, $uid); push @messages, \%info; } $IMAP->logout(); return \@messages; } sub fetch_message { # fetch a message ID, display some information my ($IMAP, $uid) = @_; my $Msg = $IMAP->fetch($uid, 'envelope')->{$uid}->{envelope}; # clean the sender $Msg->{From} =~ s/(")|(<.*>)|(\s{2,})|(\s+$)//g; # clean the subject $Msg->{Subject} =~ s/\[[[:alpha:]]+#\d{6}\]//g; $Msg->{Subject} =~ s/(\(.*\))|(\s{2,})|(\s+$)|(^\s+)//g; return ( From => $Msg->{From}, Subject => $Msg->{Subject}); } my $messages = find_messages(); if (scalar (@$messages) > 0) { foreach my $msg (@$messages) { print $msg->{From}, " - ", $msg->{Subject}, "\n"; } } else { print "No mail"; }

just another cpan module author

In reply to Is my email worth reading? by spatterson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.