使用全局变量作为Mail :: IMAPClient的参数 [英] Using a global variable as parameter to Mail::IMAPClient

查看:68
本文介绍了使用全局变量作为Mail :: IMAPClient的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用perl制作一个邮件批量下载器,该下载器将连接多个帐户并下载其附件,但我仍在学习这种语言.我在存储在文本文件读取中的凭据有问题.每当我将参数作为字符串传递时,我都可以连接到我的帐户并检索有关未读电子邮件的信息.片段:

I'm trying to make a mail bulk downloader with perl, that will connect on multiple accounts and download it´s attachments, but i´m still learning this language. I´m having an issue with credentials stored in a text file reading. Whenever i pass the parameters as string, i can connect to my account and retrieve information about unread emails. Snippet:

my $imap = Mail::IMAPClient->new(
  Server   => 'mail.example.com',
  User     => 'nicolas',
  Password => 'password',
  Uid      => 1,
) or die "Erro ao conectar na conta";

它连接起来,并且将my @mails = ($imap->unseen);foreach循环一起使用,我可以将我所有看不见的邮件都放在列表中.

It connects, and using my @mails = ($imap->unseen); with a foreach loop i can get all my unseen mails on a list.

但是,如果我尝试从文件中获取凭据并分配给变量,然后将该变量用作$imap的凭据,则它将失败:

However, if i try to get my credentials from a file and assign to a variable and further use this variable as credentials to $imap it fails:

foreach my $line ( @lines ) {
  my @credentials = split( /\s+/, $line );
  my $domain = $credentials[0];
  my $account = $credentials[1];
  my $password = $credentials[2];

my $imap = Mail::IMAPClient->new(
  Server   => 'mail.example.com',
  User     => $account,
  Password => $password,
  Uid      => 1,) 
}

当我运行脚本时,我收到以下消息:

When i run the script i get this message:

$ ./folder_list.pl
Can't call method "select" on an undefined value at ./folder_list.pl line 43.

如果我print "$account", "$password";,我可以检查其值,但不能将其用作$imap的参数.我在这里想念什么?

If i print "$account", "$password"; i can check its values, but cant use them as parameters of $imap. What am i missing here?

推荐答案

很奇怪.将perl升级到pel-5.8.8-43.el5_11并将库升级到perl-Mail-IMAPClient-3.37-1.el5perl-Email-MIME-1.903-2.el5.rf后,在el5(CentOS)上解决了问题.不知道是他们的女巫引起了问题,但问题解决了.

Weird. Problem solved on el5(CentOS) after upgrading perl to pel-5.8.8-43.el5_11 and the libs to perl-Mail-IMAPClient-3.37-1.el5 and perl-Email-MIME-1.903-2.el5.rf. Don´t know witch of them was causing the problem but, it solved.

代码仍然相同:

  # Faz a conexão com a conta. Se não der certo passa pra próxima
  my $imap = Mail::IMAPClient->new(
    Server   => $mailserver,
    User     => $account,
    Password => $password,
    Uid      => 1) or ($log_script->log("$hora: Erro de autenticação na conta $account. Verifique as credenciais") and next);

这篇关于使用全局变量作为Mail :: IMAPClient的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆