Skip Menu |

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

Report information
The Basics
Id: 58544
Status: resolved
Priority: 0/
Queue: Mail-Box

People
Owner: Nobody in particular
Requestors: skangas [...] skangas.se
Cc:
AdminCc:

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



Subject: PATCH: Make Mail::Message::Body::Lines handle messages with empty body
Date: Sun, 20 Jun 2010 11:20:12 +0200
To: bug-Mail-Box [...] rt.cpan.org
From: Stefan Kangas <skangas [...] skangas.se>
While parsing messages in an Mbox, if a message with an empty body is encountered, the parsing stops with the following message (assuming logging is enabled): NOTICE: Close parser for file /home/skangas/Mail/archive/mail/2009-10 There are two related issues in play here. 1. Parsing fails on empty body even if there is a header "Lines: 0". The attached patch fixes this by making Mail::Message::Body::Lines properly properly handle the case with "Lines: 0" and an empty body. 2. When one message fails, parsing stops prematurely with no warning. I think it would be wise to warn the user when this happens lest she risk losing data. I have successfully used this code to parse a small mailbox (~150 messages) in Mbox format. Since I am not familiar with nor have access to mailboxes in any other relevant formats, I have no way of verifying it works for them. The test suite still passes though. Thanks, Stefan Kangas
--- Mail-Box-2.094/lib/Mail/Message/Body/Lines.pm 2010-04-06 11:17:26.000000000 +0200 +++ Mail-Box-2.094p1/lib/Mail/Message/Body/Lines.pm 2010-06-20 09:31:42.000000000 +0200 @@ -104,12 +104,16 @@ #------------------------------------------ sub read($$;$@) -{ my ($self, $parser, $head, $bodytype) = splice @_, 0, 4; +{ my ($self, $parser, $head, $bodytype, $lines_header) = splice @_, 0, 5; my ($begin, $end, $lines) = $parser->bodyAsList(@_); - $lines or return undef; $self->fileLocation($begin, $end); - $self->{MMBL_array} = $lines; + if (defined $lines_header && $lines_header == 0) { + $self->{MMBL_array} = []; + } else { + $lines or return undef; + $self->{MMBL_array} = $lines; + } $self; }
Subject: Re: [rt.cpan.org #58544] PATCH: Make Mail::Message::Body::Lines handle messages with empty body
Date: Mon, 21 Jun 2010 09:33:33 +0200
To: Stefan Kangas via RT <bug-Mail-Box [...] rt.cpan.org>
From: Mark Overmeer <solutions [...] overmeer.net>
* Stefan Kangas via RT (bug-Mail-Box@rt.cpan.org) [100621 00:17]: Show quoted text
> Sun Jun 20 20:17:47 2010: Request 58544 was acted upon. > Transaction: Ticket created by skangas@skangas.se > Queue: Mail-Box > Subject: PATCH: Make Mail::Message::Body::Lines handle messages with empty body > > While parsing messages in an Mbox, if a message with an empty body is > encountered, the parsing stops with the following message (assuming > logging is enabled): > NOTICE: Close parser for file /home/skangas/Mail/archive/mail/2009-10 > > There are two related issues in play here. > 1. Parsing fails on empty body even if there is a header "Lines: 0".
The parser did not get changed in many years, and is in use by a lot of serious applications.... but no-one ever encountered this. I'll investigate. The patch you propose it probably not the way to go. I think it has to do with overloading, somewhere, where body "undef" is tested, where body==0 returns false as well. Show quoted text
> 2. When one message fails, parsing stops prematurely with no warning.
You probably mean: "fails on an empty message", because there are a few ways it can fail with error message. -- Thanks for the report, 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 #58544] PATCH: Make Mail::Message::Body::Lines handle messages with empty body
Date: Mon, 21 Jun 2010 10:56:23 +0200
To: bug-Mail-Box [...] rt.cpan.org
From: Stefan Kangas <skangas [...] skangas.se>
"Mark Overmeer via RT" <bug-Mail-Box@rt.cpan.org> writes: Show quoted text
> The patch you propose it probably not the way to go. I think it has > to do with overloading, somewhere, where body "undef" is tested, > where body==0 returns false as well.
I believe the place where we silently fail on empty messages is line 564 of lib/Mail/Message.pm. Indeed, that is not a check for undef. Changing it to check for undef does not fix this issue though, since this is what readMessage returns on an empty body, due to the following: lib/Mail/Box/Parser/Perl.pm:172: if(!@$lines) { $lines = undef } Stefan Kangas
fixed in 2.095 (will be released today)