http://www.perlmonks.org?node_id=546624


in reply to More efficient way to get unseen IMAP messages

The more eficient is use of STATUS command of imap protocol. But itīs not available on Net::IMAP::Simple...

Can you implement a hack todo it.

1. Examing the protocol:

0 LOGIN mda "xxxxxx" 0 OK LOGIN Ok. 1 STATUS "INBOX" (UNSEEN MESSAGES) * STATUS "INBOX" (MESSAGES 84 UNSEEN 78) 1 OK STATUS Completed. 2 LOGOUT * BYE Courier-IMAP server shutting down 2 OK LOGOUT completed

2. Understanding module struture (and how Net::IMAP implements):

sub login { my ( $self, $user, $pass ) = @_; return $self->_process_cmd ( cmd => [LOGIN => qq[$user "$pass"]], final => sub { 1 }, process => sub { }, ); }
3. Suggested hack:
package Net::IMAP::Simple; sub unseen { my ( $self, $mbox ) = @_; my $unseen = 0; $mbox ||= "INBOX"; $self->_process_cmd ( cmd => [STATUS => "\"$mbox\"" . " (UNSEEN)" ], final => sub { }, process => sub { $unseen = $1 if ( $_[0] =~ /UNSEEN\s+(\d+)/ ); } ); return $unseen; }

4. Resume:
Examine the module options on code and protocol to improve your process ;)

on time Mail::IMAPClient suggest from davidrw implements many others functions...

--
Marco Antonio
Rio-PM