2

Mail::IMAPClient->new()在 Windows 7 中冻结:

sub connectGMail
{
    my $client = Mail::IMAPClient->new
    (
        Server   => 'imap.gmail.com',
        Port     => 993,
        Ssl      =>  1,
        User     => 'whateverUser',
        Password => 'aG00dP455w0rd',
        Socket   => IO::Socket::SSL->new
        (       
            SSL_verify_mode => SSL_VERIFY_NONE
        )
    )
    or die "Cannot connect  ($@)\n";
    return $client;
}

我尝试停用 Windows 防火墙,但没有任何改变。

一个非常相似的代码在 Linux 中运行良好:

sub connectGMail
{
    my $client = Mail::IMAPClient->new
    (
        Server   => 'imap.gmail.com',
        Port     => 993,
        Ssl      =>  1,
        User     => 'whateverUser',
        Password => 'aG00dP455w0rd'
    )
    or die "Cannot connect  ($@)\n";
    return $client;
}

在这两种情况下Mail::IMAPClient,都可以从 CPAN 存储库正常安装,但在 Windows 中,如果我不包含Socket选项,它会向我显示此警告

*******************************************************************
 Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
 is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
 together with SSL_ca_file|SSL_ca_path for verification.
 If you really don't want to verify the certificate and keep the
 connection open to Man-In-The-Middle attacks please set
 SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************

并且脚本的其余部分(解析电子邮件)将无法正常工作。

error:    unexpected end of header


error:    unexpected end of header


error:    unexpected end of header

任何帮助将不胜感激,在此先感谢。

4

1 回答 1

2

看起来Mail::IMAPClient->new不喜欢套接字和服务器/端口。如果我使用服务器/端口创建套接字然后传递它,它确实连接成功。

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;
}
于 2013-03-25T22:12:52.407 回答