Subject: | get_summaries fails to parse complex reply |
The simple script below fails with the error
Odd number of elements in hash assignment at
/usr/share/perl5/Net/IMAP/Client.pm line 389, <GEN0> line 14.
Can't call method "message_id" on unblessed reference at ./imap.pl line
24, <GEN0> line 14.
Looks like _parse_token fails to parse the complex reply which I
attached (redacted for privacy).
Net::IMAP::Client: 0.95
Perl: 5.10.1
OS: Linux TreeHouse 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17
UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
IMAP Server: [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE
THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION
STARTTLS] Courier-IMAP ready. Copyright 1998-2011 Double Precision, Inc.
See COPYING for distribution information.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Net::IMAP::Client;
my $imap = Net::IMAP::Client->new(
server => $ARGV[0],
user => $ARGV[1],
pass => $ARGV[2],
) or die;
$imap->login() or die $imap->last_error;
$imap->select('INBOX');
my $messages = $imap->search('ALL');
my %ids;
foreach my $m (@$messages) {
my $id = $imap->get_summaries($m, 'Message-Id')->message_id;
$ids{$id} = $m;
}
print Dumper(\%ids);
Subject: | imap.txt |
NIC4 UID FETCH 190 (UID FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODYSTRUCTURE BODY.PEEK[HEADER.FIELDS (Message-Id)])
* 1 FETCH (UID 190 FLAGS (\Seen) INTERNALDATE "13-Jun-2011 13:45:39 +0200" RFC822.SIZE 3228655 ENVELOPE ("Mon, 13 Jun 2011 13:45:00 +0200" "LLLLLLL / IIIIIIIIII pictures" (("LLLLLLL" NIL "bbbbblllllll" "gmail.com")) (("LLLLLLL" NIL "bbbbblllllll" "gmail.com")) (("LLLLLLL" NIL "bbbbblllllll" "gmail.com")) (("'LLLLLLL, Oooooo Nnnn'" NIL "oooooo.nnnn" "lllllll.de")) (("'LLLLLLL, Sssssss Gggggggggg'" NIL "sssssss.gggggggggg" "lllllll.de")("'Hh, Jjjjjj'" NIL "hh" "lllllll.com.cn")("'LLLLLLL,JP '" NIL "jjjj_pppp" "lllllll.com.cn")("'Iiiiiii Lllllll'" NIL "iiiiiii.lllllll" "lllllll.de")) NIL NIL "<002a01cc29bf$5536d150$ffa473f0$@com>") BODYSTRUCTURE (((("text" "plain" ("charset" "us-ascii") NIL NIL "7bit" 993 37 NIL NIL NIL)("text" "html" ("charset" "us-ascii") NIL NIL "quoted-printable" 4584 105 NIL NIL NIL) "alternative" ("boundary" "----=_NextPart_002_002D_01CC29D0.18BFC860") NIL NIL)("image" "png" ("name" "image001.png") "<image001.png@01CC29D0.10207240>" NIL "base64" 3376 NIL NIL NIL) "related" ("boundary" "----=_NextPart_001_002C_01CC29D0.18BFC860") NIL NIL)("image" "jpeg" ("name" "IMG_2956 (Medium).JPG") NIL NIL "base64" 181446 NIL ("attachment" ("filename" "IMG_2956 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2957 (Medium).JPG") NIL NIL "base64" 181688 NIL ("attachment" ("filename" "IMG_2957 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2958 (Medium).JPG") NIL NIL "base64" 164326 NIL ("attachment" ("filename" "IMG_2958 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2959 (Medium).JPG") NIL NIL "base64" 208968 NIL ("attachment" ("filename" "IMG_2959 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2961 (Medium).JPG") NIL NIL "base64" 165526 NIL ("attachment" ("filename" "IMG_2961 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2964 (Medium).JPG") NIL NIL "base64" 203590 NIL ("attachment" ("filename" "IMG_2964 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2967 (Medium).JPG") NIL NIL "base64" 184122 NIL ("attachment" ("filename" "IMG_2967 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2968 (Medium).JPG") NIL NIL "base64" 220490 NIL ("attachment" ("filename" "IMG_2968 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2972 (Medium).JPG") NIL NIL "base64" 195716 NIL ("attachment" ("filename" "IMG_2972 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2974 (Medium).JPG") NIL NIL "base64" 219436 NIL ("attachment" ("filename" "IMG_2974 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2978 (Medium).JPG") NIL NIL "base64" 179392 NIL ("attachment" ("filename" "IMG_2978 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_2993 (Medium).JPG") NIL NIL "base64" 179310 NIL ("attachment" ("filename" "IMG_2993 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_3002 (Medium).JPG") NIL NIL "base64" 199456 NIL ("attachment" ("filename" "IMG_3002 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_3010 (Medium).JPG") NIL NIL "base64" 110058 NIL ("attachment" ("filename" "IMG_3010 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_3015 (Medium).JPG") NIL NIL "base64" 223180 NIL ("attachment" ("filename" "IMG_3015 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_3032 (Medium).JPG") NIL NIL "base64" 192530 NIL ("attachment" ("filename" "IMG_3032 (Medium).JPG")) NIL)("image" "jpeg" ("name" "IMG_3035 (Medium).JPG") NIL NIL "base64" 203256 NIL ("attachment" ("filename" "IMG_3035 (Medium).JPG")) NIL) "mixed" ("boundary" "----=_NextPart_000_002B_01CC29D0.18BFA150") NIL "de") BODY[HEADER.FIELDS ("Message-Id")] {53}
Message-ID: <002a01cc29bf$5536d150$ffa473f0$@com>
)
NIC4 OK FETCH completed.