Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl use strict; use Net::IMAP::Simple; # This is the folder separator your IMAP server uses. # NOTE: Not used yet. my $separator = "."; # IMAP Account Details my %servers = ( 'imap.server.1' => [ 'username' , 'password' ] , # 'imap.server.2' => [ 'username' , 'password' ] # ... ); my $mailbox_name; my $new_messages; my $total_messages; # Define the format rules format Mailboxes_Top = Mailbox New Total -------------------------------------------- -------- -------- . format Mailboxes_Footer = -------------------------------------------- -------- -------- Total @<<<<<<< @<<<<<<< $new_messages $total_messages -------------------------------------------- -------- -------- . format Mailboxes = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<< @<<<<<<< $mailbox_name $new_messages $total_messages . # For each server... foreach my $s (keys %servers){ # Fetch the username my $u = @{$servers{$s}}[0]; # Fetch the password my $p = @{$servers{$s}}[1]; # Output the heading $~ = 'Mailboxes_Top'; write; # Open a connection to the IMAP server my $server = new Net::IMAP::Simple( $s ); $server->login ( $u , $p ); # Get a list of all the mailboxes my @folders = $server->mailboxes(); # Reset the message counters my $total_account_messages = 0; my $total_new_messages = 0; # For each folder on the server... foreach(sort @folders){ # Select the folder and get the number of messages my $folder_messages = $server->select($_); # Increment the total message counter $total_account_messages += $folder_messages; # For each message in the folder check if it is new my $folder_new_messages = 0; foreach my $msg (1 .. $folder_messages){ $folder_new_messages++ if (!$server->seen($msg +)); }; # Increment the total new message counter $total_new_messages += $folder_new_messages; # Prepare the folder name for pretty output my $title = $_; my @tmp = split(/\./, $title); my $start = " " x $#tmp; $title = $start . pop(@tmp); # Output the current folder details $~ = 'Mailboxes'; $mailbox_name = $title; $new_messages = $folder_new_messages; $total_messages = $folder_messages; write; } # Output the footer $~ = 'Mailboxes_Footer'; $new_messages = $total_new_messages; $total_messages = $total_account_messages; write; }

In reply to 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 musing on the Monastery: (4)
As of 2024-04-16 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found