这就是我使用 yo GMail 连接的方式Mail::IMAPClient
sub connectGMail
{
my $socket = IO::Socket::SSL->new
(
PeerAddr => 'imap.gmail.com',
PeerPort => 993,
SSL_verify_mode => SSL_VERIFY_NONE
)
or die "socket(): $@";
my $client = Mail::IMAPClient->new
(
User => 'whateverUser',
Password => 'aG00dP455w0rd'
Socket => $socket
)
or die "Cannot connect ($@)\n";
return $client;
}
然后我将此客户端对象传递给processEmails
子程序
sub processEmails
{
my $client = shift;
if ($client->IsAuthenticated())
{
$client->select('Pruebas');
my @messages = $client->messages();
my $mime_parser = getMIMEParser();
my $filer = MIME::Parser::FileInto->new();
mkdir(EXTRACT_DIR);
for(@messages)
{
my $msg_body = $client->message_string($_);
my $msg_subject = Encode::decode('MIME-Header', $client->subject($_));
if ($msg_body)
{
my $dir = EXTRACT_DIR . "/" . $msg_subject;
$filer->init($dir);
mkdir($dir);
$mime_parser->filer($filer);
my $ok = parseEmail($mime_parser, $msg_body);
if ($ok)
{
print(STDERR "Email \"$msg_subject\" parsed OK\n");
}
}
else
{
print(STDERR "No body for message with subject $msg_subject\n");
}
}
}
else
{
print(STDERR "Something nasty happened\n");
}
}
问题是$msg_body
(使用 检索message_string
)对于所有消息都是空的,但是$msg_subject
是正确的,这意味着连接正常。这是输出:
No body for message with subject íQuÚ pasa!
No body for message with subject Prueba con formateo HTML