Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: polettix [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 3.02
Fixed in: (no value)



Subject: get_bodystructure() breaks with ALTERNATIVE and MIXED messages
get_bodystructure() method breaks when called upon a multipart/alternative message. I tracked it a bit and it seems to be a problem in the grammar for BodyStructure. For non-alternative messages, the answer to a BODYSTRUCTURE fetch is something like: * 23 FETCH (UID 58 BODYSTRUCTURE ("TEXT" "PLAIN" ("charset" "iso-8859-1") which parses correctly. OTOH, when the message has ALTERNATIVE, the parser breaks, like with the following (as got from Gmail, so you can verify easily): * 1 FETCH (UID 1 BODYSTRUCTURE (("TEXT" "PLAIN" ("charset" "ISO-8859-1") NIL NIL "quoted-printable" 1744 0)("TEXT" "HTML" ("charset" "ISO-8859-1") NIL NIL "quoted-printable" 1967 0) "ALTERNATIVE")) I'm attaching the RD_TRACE for the parsing of the above string. There is a similar issue with MIXED messages as well. I'm also attaching a script that allows you to verify the bug. You'll need a gmail account with some messages in the inbox; you can call it as follows: shell$ perl imap-bug.pl yourname yourpass to get the list of messages (so that you can take the UID of the message you want to investigate), and: shell$ perl imap-bug.pl yourname yourpass uid to call get_bodystructure().
Subject: imap-bug.pl
#!/usr/bin/env perl use strict; use warnings; use Mail::IMAPClient; use IO::Socket::SSL; use List::Util qw( first ); my ($username, $password, $uid) = @ARGV; # Connect to the IMAP server via SSL and get rid of server greeting message my $socket = IO::Socket::SSL->new( PeerAddr => 'imap.gmail.com', PeerPort => 993, ) or die "socket(): $@"; # Build up a client attached to the SSL socket and login my $client = Mail::IMAPClient->new( Socket => $socket, User => $username, Password => $password, ) or die "new(): $@"; print "I'm authenticated\n" if $client->IsAuthenticated(); my $folder = 'Inbox'; $client->select($folder) or die "Could not select: $@"; my $msgcount = $client->message_count($folder); die "could not message_count(): $@" unless defined $msgcount; print "there are $msgcount (s) in $folder\n"; if ($uid) { my $s = $client->get_bodystructure($uid) or die "you hit a bug!\n"; require Data::Dumper; print Data::Dumper::Dumper($s); } else { print first {m/BODYSTRUCTURE\s+\(/i} $client->fetch($_, 'BODYSTRUCTURE') for $client->search('ALL'); } $client->logout();
Subject: rdtrace
Download rdtrace
application/octet-stream 105.7k

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #31964] get_bodystructure() breaks with ALTERNATIVE and MIXED messages
Date: Sat, 29 Dec 2007 23:39:09 +0100
To: Flavio Poletti via RT <bug-Mail-IMAPClient [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Flavio Poletti via RT (bug-Mail-IMAPClient@rt.cpan.org) [071228 14:45]: Show quoted text
> Fri Dec 28 09:45:17 2007: Request 31964 was acted upon. > Transaction: Ticket created by POLETTIX > Queue: Mail-IMAPClient > Subject: get_bodystructure() breaks with ALTERNATIVE and MIXED messages > Broken in: 3.02 > Severity: Normal > Owner: Nobody > Requestors: polettix@cpan.org > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=31964 > > > > get_bodystructure() method breaks when called upon a > multipart/alternative message. I tracked it a bit and it seems to be a > problem in the grammar for BodyStructure.
Oops. The trace says that it is accepted, but as the wrong thing. In 2.99_06, Gerald Richter had contributed some changes in the parsing... probably something got broken... Have spend some time, but bed is calling. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: Re: [rt.cpan.org #31964] get_bodystructure() breaks with ALTERNATIVE and MIXED messages
Date: Mon, 31 Dec 2007 10:31:52 +0100
To: Flavio Poletti via RT <bug-Mail-IMAPClient [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Flavio Poletti via RT (bug-Mail-IMAPClient@rt.cpan.org) [071228 14:45]: Show quoted text
> Fri Dec 28 09:45:17 2007: Request 31964 was acted upon. > Transaction: Ticket created by POLETTIX > Queue: Mail-IMAPClient > Subject: get_bodystructure() breaks with ALTERNATIVE and MIXED messages > Broken in: 3.02 > Severity: Normal > Owner: Nobody > Requestors: polettix@cpan.org > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=31964 > > > get_bodystructure() method breaks when called upon a > multipart/alternative message. I tracked it a bit and it seems to be a > problem in the grammar for BodyStructure.
I have a more clear moment now, than in my previous reply. Apperently, most servers do provide additional info about multiparts. I think I have a fix. At the same time, I clean-up the grammar. It contains quite weird constructs, like $return || defined $return; -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
fix released in 3.03