Skip Menu |

This queue is for tickets about the Mail-IMAPClient CPAN distribution.

Report information
The Basics
Id: 76989
Status: resolved
Priority: 0/
Queue: Mail-IMAPClient

People
Owner: PLOBBES [...] cpan.org
Requestors: pierluigi.frullani [...] frumar.it
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 3.36



Subject: "Can't call method "bodytype" on an undefined value" on Mail::IMAPClient::BodyStructure
Date: Fri, 4 May 2012 16:25:45 +0200
To: bug-Mail-IMAPClient [...] rt.cpan.org
From: Pierluigi Frullani <pierluigi.frullani [...] frumar.it>
When using this snippet: =========================================================== #!/usr/local/bin/perl use Mail::IMAPClient::BodyStructure; use Mail::IMAPClient; my $imap = Mail::IMAPClient->new( Server => "server", User => "user", Password => "pwd", Uid => 1 ); $imap->select("INBOX") or die "cannot select the inbox for $usr: $@\n"; my @recent = $imap->messages or die "Could not messages: $@\n"; foreach my $id (@recent) { my $subject = $imap->subject($id); print $subject."\n"; my $fetched = $imap->fetch($id, "bodystructure"); if (!defined $fetched){ print "Not defined fetched\n"; } my $struct = Mail::IMAPClient::BodyStructure->new($fetched); if (!defined $struct){ print "Not defined struct\n"; } my $mime = $struct->bodytype."/".$struct->bodysubtype; my $parts =join "\n\t", $struct->parts; print "Msg $id (Content-type: $mime) contains these parts:\n\t$parts\n"; } =========================================================== $struct object is always undefined, thus I always get error at: "my $mime = $struct->bodytype."/".$struct->bodysubtype;" For what I have seen, in BodyStructure.pm, at line 19, when the parser get called, it always return undef. As you can see the $fetched array is defined ( I've put a check for it and is defined ), but the new($fetched) returns undef. Any idea on what can be ? I checked against cyrus and exchange 2007 imap servers with same results. perl -v This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi Mail-IMAPClient-3.31 from cpan.org uname -a Linux topolinux 2.6.39.3-kdump #8 SMP Thu Feb 23 23:51:30 CET 2012 x86_64 Intel(R) Core(TM)2 CPU T7200 @ 2.00GHz GenuineIntel GNU/Linux Sorry, not able to patch it .... Pierluigi
On Fri May 04 10:24:53 2012, pierluigi.frullani@frumar.it wrote: ... Show quoted text
> my $fetched = $imap->fetch($id, "bodystructure");
Sorry. It appears you hit a documentation bug that was likely introduced in 2.x to 3.x changes. The line above is the problem. When I try to do what you did, I get a warning like this: Not a SCALAR reference at .../lib/Parse/RecDescent.pm line ... On success $fetched will contain an array reference (this is documented properly...), but the following call then is wrong: Show quoted text
> my $struct = Mail::IMAPClient::BodyStructure->new($fetched);
In this case, $fetched should be a SCALAR not an array ref. You can fix this in a few ways: # return results in a list context 1) my ($fetched) = $imap->fetch($id, "bodystructure"); OR # pull first value out of arrayref returned via fetch 2) my $struct = Mail::IMAPClient::BodyStructure->new($fetched->[0]); I've patched the docs for the next release. Thank you for reporting this bug!
I just realized I still have the documentation wrong... this will be fixed in the next release!
Updated the example with the following change: https://github.com/plobbes/mail-imapclient/commit/a435d0da635602e69c5c5632ef8df909dd40d86d This will be included in the next release.