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;
}