Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: huttman [...] lucmedia.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 3.00
Fixed in: 3.29



Subject: ENVELOPE as part of fetch_hash doesn't process
I am using Version 3.25 (comes with Ubuntu package) Perl version 5.10.1 Ubuntu I would like to be able to do the following code: (already have logged into imap server represented by $imap) $imap->select("INBOX"); my $hashref = {}; $imap->fetch_hash("ENVELOPE", $hashref); Unfortunately, when "ENVELOPE" is part of fetch_hash you get the following: Use of uninitialized value $_ in pattern match (m//) at /usr/share/perl5/Mail/IMAPClient.pm line 2238. It IS getting the envelope, as $hashref->{UID}->{ENVELOPE} contains the actual envelope string for example "date" "subject" ((FROM)) .... It's just throwing this error. Additionally - it would be nice to be able to get an M:I:B:Envelope object from the envelope string. Calling M:I:B:E will not work unless you wrap the envelope string in something like: '* 0 FETCH (UID 0 ENVELOPE (' . $e2 . '))' # where $e2 is the envelope string in this example. I understand why it doesn't work, and my hack works for me, but I could understand where someone else would want to do a ->fetch_hash that includes ENVELOPE as one of the variables and be able to use that Envelope data without having to individually fetch the messages, or the BODY or anything else. Including RFC822.SIZE or INTERNALDATE in the fetch_hash gets usable info since those are just strings, but there should be a convenience method for dealing with ENVELOPE if that string is returned. Thanks! Great module.
This is definitely a reasonable enhancement request. I'm not sure when I'll get to it just yet but I'll definitely keep it open until I get a chance to do the work. Patches are always welcome ;-).
Subject: Re: [rt.cpan.org #69876] ENVELOPE as part of fetch_hash doesn't process
Date: Tue, 09 Aug 2011 00:26:00 -0400
To: bug-Mail-IMAPClient [...] rt.cpan.org
From: Phil Pearl (Lobbes) <phil [...] perkpartners.com>
Chris H via RT <bug-Mail-IMAPClient@rt.cpan.org> wrote: Show quoted text
> Fri Jul 29 00:54:40 2011: Request 69876 was acted upon. > Transaction: Ticket created by chrisishardcore > Queue: Mail-IMAPClient > Subject: ENVELOPE as part of fetch_hash doesn't process
... Show quoted text
> Unfortunately, when "ENVELOPE" is part of fetch_hash you get the > following: > Use of uninitialized value $_ in pattern match (m//) at > /usr/share/perl5/Mail/IMAPClient.pm line 2238.
Ok, I looked a bit closer. This error goes away after 3.25 as 3.26 added more robust parsing. ... Show quoted text
> Additionally - it would be nice to be able to get an M:I:B:Envelope > object from the envelope string. Calling M:I:B:E will not work unless > you wrap the envelope string in something like: > '* 0 FETCH (UID 0 ENVELOPE (' . $e2 . '))' # where $e2 is the envelope > string in this example. > > I understand why it doesn't work, and my hack works for me, but I > could understand where someone else would want to do a ->fetch_hash > that includes ENVELOPE as one of the variables and be able to use that > Envelope data without having to individually fetch the messages, or > the BODY or anything else. Including RFC822.SIZE or INTERNALDATE in > the fetch_hash gets usable info since those are just strings, but > there should be a convenience method for dealing with ENVELOPE if that > string is returned.
Below you will find my proposed patch for a convenience method. With it you could do something like this: my $href = $imap->fetch_hash("ENVELOPE"); foreach my $id (sort keys %$href) { my $bs = Mail::IMAPClient::BodyStructure::Envelope->parse_string( $href->{$id}->{ENVELOPE} ); } Convenient enough? Phil The proposed patch (the changes are inside the Mail::IMAPClient::BodyStructure::Envelope package) ... $ git diff diff --git a/lib/Mail/IMAPClient/BodyStructure.pm b/lib/Mail/IMAPClient/BodyStructure.pm index 0a91d2b..589fd9c 100644 --- a/lib/Mail/IMAPClient/BodyStructure.pm +++ b/lib/Mail/IMAPClient/BodyStructure.pm @@ -164,6 +164,12 @@ sub new $parser->envelope($envelope); } +sub parse_string +{ my ($class, $envelope) = @_; + $envelope = "(" . $envelope . ")" unless ( $envelope =~ /^\(/ ); + $parser->envelopestruct($envelope); +} +
Mail::IMAPClient 3.29 was released today with the patch for this bug, please feel free to reopen if you find the problem still exists in this release.