Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found