I wrote a similar scriptusing Mail::IMAPClient, which I've liked a lot and found really easy to use and well doc'd.
Looks like (w/o actually trying it) adding SSL support would be trivial with Net::IMAP::Simple::SSL.
Here's my script (just a warning this is a quick & dirty solution, but suits my purposes) that i call 'nfrm' (i used to use that elm command all the time when i used pine) -- called by itself (no params), it will list new messages; called with a message index, it will print that message to the screen:
[david@host david]$ nfrm
1 [INBOX] This is the Subject
[david@host david]$ nfrm 1
1 [INBOX] This is the Subject
=====> sender@from.somewhere.com (Some Guy)
This is the message text ...
#!/usr/bin/perl
my $N = $ARGV[0] || 0;
use Mail::IMAPClient;
use strict;
my ($host, $id, $pass) = qw( YOURMAIL.HOSt.COM YOURNAME YOURPW );
my $imap = Mail::IMAPClient->new(
Server => $host,
User => $id,
Password=> $pass,
) or die "Cannot connect to $host as $id: $@";
my $ct = 0;
my @allMsgs;
foreach my $folder ( $imap->folders ){
$imap->select($folder);
$imap->Peek(1);
my @msgs = grep $_, $imap->unseen();
next unless scalar @msgs;
push @allMsgs, { folder => $folder, msgs => \@msgs };
$ct += scalar (@msgs);
}
foreach my $h (@allMsgs){
my $folder = $h->{folder};
my @msgs = @{$h->{msgs}};
$imap->select($folder);
$imap->Peek(1);
foreach my $msgId ( reverse @msgs ){
printf "%-2d [%s] %s\n", $ct, $folder, $imap->subject($msgId) unle
+ss $N && $ct != $N;
printf "=====> %s\n%s", $imap->get_header($msgId, 'From'), $imap->
+body_string($msgId) if $ct == $N;
$ct--;
}
}
|