Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'm trying to write a fairly simple IMAP "polling" utility. The script iterates through the specified IMAP mail folders and displays the number of unread messages over the total number of messages. I'm using Net::IMAP::Simple::SSL since SSL access is imperative in my environment. Here's the snippet I use to get the number of "new" messages:
for (my $i = 1; $i <= $tmessages; $i++) { if (!$imap->seen($i)) { $nmessages++; } }
$tmessages, as you can probably guess, is the total number of messages. This works really well with small folders, even foldes with a few hundred messages, but once you hit the thousands it begins to take a fair amount of time. I looked at Mail::IMAPClient, and the 'unseen_count' method looks like it could be useful. However, IMAPClient doesn't appear to have any SSL support "out of the box." I have to admit, my knowledge is severely lacking when it comes to SSL communication in Perl. I tried this snippet, and it complained extensively:
use IO::Socket::SSL; use Mail::IMAPClient; $socket = new IO::Socket::SSL("my.mailserver:imaps"); $imap = Mail::IMAPClient->new(Socket => $socket, User => $user, Password => $pass,) or die "Couldn't connect to IMAP server $host as $user: $@\n"; if (!$imap->login) { die "Couldn't authenticate: $@\n"; }
If someone could point me at a more efficient way of getting the unread messages count, or working with IMAP SSL in Mail::IMAPClient, it'd be immensely appreciated! Thanks!

In reply to More efficient way to get unseen IMAP messages by captkirk

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, 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, 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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (4)
    As of 2020-02-28 22:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?










      Results (127 votes). Check out past polls.

      Notices?