1

我正在使用此脚本从 gmail 帐户获取所有消息:

#!/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";

在 gmail 帐户中,大约有 1.500 条消息……但总是 $pop->Count() 返回 250 或更多……绝不是 1.500。

有人知道这件事吗?

提前致谢。

4

1 回答 1

2

最后,我使用 IMAP 代替 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();

这工作很棒。

于 2012-12-17T20:59:09.167 回答