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";
It connects, and using my @mails = ($imap->unseen);
with a foreach
loop i can get all my unseen mails on a list.
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.
If i print "$account", "$password";
i can check its values, but cant use them as parameters of $imap
. What am i missing here?
I suspect that there's an empty line at end your file. This loop you have in question loops over all lines and file, remembers only last one and then constructs
IMAPClient
with that data. If you construct it with empty account/password you are likely to get errors like those you've mentioned.Drop
our
and usemy
and move processing into the loop to, because I understand that's exactly what you want - do IMAP processing with every account.Weird. Problem solved on
el5
(CentOS) after upgrading perl topel-5.8.8-43.el5_11
and the libs toperl-Mail-IMAPClient-3.37-1.el5
andperl-Email-MIME-1.903-2.el5.rf
. Don´t know witch of them was causing the problem but, it solved.Code still the same: