#!/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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is my email worth reading?
by okram (Monk) on Feb 12, 2008 at 18:38 UTC | |
|
Re: Is my email worth reading?
by telemachus (Friar) on Apr 02, 2008 at 01:41 UTC | |
|
Re: Is my email worth reading?
by sv87 (Acolyte) on Aug 19, 2008 at 22:40 UTC |