我正在处理一个perl脚本,它将连接到Gmail并下载所有电子邮件。请记住,我现在只专注于连接到Gmail,所以现在只能设置脚本循环浏览一些文件夹。这是我到目前为止有:Perl Mail ::具有IO :: Socket :: SSL帮助的IMAPClient
#!/usr/bin/perl
use strict;
use warnings;
use Mail::IMAPClient;
use IO::Socket::SSL;
# Connect to IMAP via SSL and get rid of greeting message
my $socket = IO::Socket::SSL->new(
PeerAddr => 'imap.gmail.com',
PeerPort => 993,
)
or die "Socket(): [email protected]";
my $greeting = <$socket>;
my ($id, $answer) = split /\s+/, $greeting;
die "Problems loggin in: $greeting" if $answer ne 'OK';
# Build a client attached to the SSL Socket and login
my $client = Mail::IMAPClient->new(
Socket => $socket,
User => '[email protected]',
Password => 'password',
Port => 993,
)
or die "new(): [email protected]";
my ($code, $output) = ("","");
until($code) {
$output = $client->_read_line or return undef;
for my $o (@$output) {
$client->_debug("Connect: Recieved this from readline: ".join("/",@$o)."\n");
$client->_reord($client->Count,$o);
next unless $o->[Mail::IMAPClient::TYPE] eq "OUTPU";
($code) = $o->[Mail::IMAPClient::DATA] =~ /^\*\s+(OK|BAD|NO)/i ;
}
}
if($code =~ /BYE|NO /) {
$client->State("Unconnected");
die "IMAP server disconnected";
}
$client->login;
print "1";
$client->select('INBOX');
my @mails = ($client->seen(),$client->unseen);
foreach my $id (@mails) { print "$id\n"; }
# Terminate the connection with IMAP
$client->logout();
当我运行该脚本,但是,程序只与一个闪烁光标的很长一段时间坐。它返回绝对没有输出或错误。任何人有任何建议?
在哪条线卡住? (调试器可以帮助你,或者穷人在你的代码中散布打印语句的方法。) – Ether 2010-11-05 19:17:31
那么,分散打印命令不会返回任何输出。即使将其放在perl文件的头部也不起作用。 – 2010-11-06 01:43:01
好吧,我仍然没有工作,但我改变了上面的代码。有了这个新的代码,我得到了以下输出:未连接时尝试命令! LastError是:超时等待服务器的数据600s /usr/share/perl5/Mail/IMAPClient.pm 116行 \t Mail :: IMAPClient :: LastError('Mail :: IMAPClient = HASH(0xd57708)','NO not )在/usr/share/perl5/Mail/IMAPClient.pm行1617 \t Mail :: IMAPClient :: _ read_line('Mail :: IMAPClient = HASH(0xd57708)')调用spam.pl行32 Can不会在spam.pl第32行的子例程外面返回。 – 2010-11-06 05:50:37