perlimapclient

The returned hash from fetch_hash in Mail::IMAPClient doesn't meet the parameters I send


This is a auto answered question about a problem I had and I found no answer, the problem is the following:

use Mail::IMAPClient;
$imap = new Mail::IMAPClient(
   # My connection data.
};
#Folder selection and stuff like that.
my $hash = $imap->fetch_hash('BODY.PEEK[HEADER.FIELDS (SUBJECT)]');

Now I have a hash with the subject of the emails in the folder I selected, I had expected it to return the subject of a message writing:

print $hash->{mymessage}->{'BODY.PEEK[HEADER.FIELDS (SUBJECT)]'};

Instead I got: Use of uninitialized value in concatenation (.) or string at /var/www/localhost/htdocs/user/mail.pl line 76.

Please excuse my poor english.


Solution

  • What I did was seeing what keys $hash->{mymessage} was returning, it was BODY[HEADER.FIELDS (SUBJECT)], so I figured out Mail::IMAPClient, omit PEEK from any call to the function while creating the hash keys in the function fetch_hash(). What I should did is:

    print $hash->{mymessage}->{'BODY[HEADER.FIELDS (SUBJECT)]'};`