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--; } }

In reply to Re: Check IMAP Folders for new messages by davidrw
in thread Check IMAP Folders for new messages by chazzz

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.