Reputation: 1492
I'm using this script to get all the messages from a gmail account:
#!/usr/bin/perl
use Mail::POP3Client;
use IO::Socket::SSL;
no warnings;
my $username = 'username';
my $password = 'password';
my $mailhost = 'pop.gmail.com';
my $port = 995;
my $socket = IO::Socket::SSL->new(
PeerAddr => 'pop.gmail.com',
PeerPort => 995,
Proto => 'tcp',
)
or die "No socket!: $!\n";
my $pop = Mail::POP3Client->new();
$pop->User($username);
$pop->Pass($password);
$pop->Socket($socket);
$pop->Connect();
# me fijo cuantos hay
my $count = $pop->Count();
my $size = $pop->Size();
print "count[$count]\n";
In the gmail account there are about 1.500 messages... but always $pop->Count() return 250 or more.. never the 1.500.
Anyone knows something about this?
Thanks in advance.
Upvotes: 1
Views: 3295
Reputation: 1492
Finally, i use IMAP insteand POP.
#!/usr/bin/perl
use strict;
use warnings;
use Mail::IMAPClient;
use IO::Socket::SSL;
my $socket = IO::Socket::SSL->new(
PeerAddr => 'imap.gmail.com',
PeerPort => 993,
)
or die "socket(): $@";
my $client = Mail::IMAPClient->new(
Socket => $socket,
User => 'username',
Password => 'password',
)
or die "new(): $@";
my $cont = 1;
$client->select('INBOX');
my @mails = ($client->seen(),$client->unseen);
foreach my $id (@mails) {
my $from = $client->get_header($id, 'From');
if ($from =~ /([a-zA-Z\_\-\.0-9]+@[a-zA-Z\_\-0-9]+\.[0-9a-zA-Z\.\-\_]+)/) {
my $email = lc $1;
print "email[$email]\n";
};
};
$client->logout();
This work great.
Upvotes: 2