perl Net::IMAP::Client how to get unseen emails -
i using net::imap::client
code:
my $imap = net::imap::client->new( server => 'imap.server.com', user => $user, pass => $pass, ssl => 1, # (use ssl? default no) ssl_verify_peer => 0, # (use ca verify server, default yes) #ssl_ca_file => '/etc/ssl/certs/certa.pm', # (ca file used verify server) or # ssl_ca_path => '/etc/ssl/certs/', # (ca path used ssl) port => 993 # (but defaults sane) ) or die "could not connect imap server"; $imap->login or die('login failed: ' . $imap->last_error); $imap->select('inbox');
then tried:
my $status = $imap->status(inbox);
now have hash this:
name : inbox uidnext : 312 messages : 298 recent : 0 unseen : 1 uidvalidity : 1420542773
now want text of 1 unseen e-mail. read documentation didnt find how that.
thanks lot.
i have code know working. uses different module, may need go?
use mail::imapclient; sub get_imap { ($user, $pass) = @_; $imap = mail::imapclient->new( 'user' => $user, 'password'=> $pass, 'ssl' => 1 ) or die "imap failure: $@"; $imap->timeout(120); $imap->server('smtp.gmail.com'); $imap->connect or die "could not connect: $@\n"; $imap->select('inbox') or die "imap select error: $!"; return $imap; } sub check_msgs { ($imap) = @_; @msgs = $imap->messages or die "could not messages: $@\n"; msgitr: foreach $msg_id (@msgs) { print "looking @ msg_id $msg_id\n"; $string = $imap->body_string($msg_id); @lines = split( /[\n\r]/, $string ); print scalar @lines . " lines\n"; foreach $line (@lines) { ... } } }
(actual snippet working code, checks messages bounces)
Comments
Post a Comment