Mail-MboxParser - Small fix for Mail-MboxParser-0.55

Posted on Sat Aug 12 01:12:44 2006 by huotte
Small fix for Mail-MboxParser-0.55

Hello Tassilo,

Included below is a patch for Mail.pm (v 1.53) which is contained in the package Mail-MboxParser-0.55. It fixes a problem which caused the header() function of the Mail::MBoxParser::Mail class to return erroneous results for some mail messages.

It turns out that some Mail User Agents (notably certain versions of Outlook) place a Tab (0x09) rather than a Space (0x20) character after the ':' on some header lines. This was causing a problem in the '_split_header' subroutine because it was explicitly searching for a colon followed by a space (": ").

The new, patched version of Mail.pm avoids this problem by splitting the header line into $key and $value components at the first ':' without regard to the character that follows. Leading and trailing whitespace is then stripped from the $value component.

I hope you will find this fix acceptable and will be able to incorporate it into the next version of Mail-MBoxParser.

Thank you also once again for writing and maintaining this wonderfully useful module.

Best regards,
<ED>

diff -Naur old/Mail.pm new/Mail.pm --- old/Mail.pm 2005-12-08 10:11:20.000000000 +0000 +++ new/Mail.pm 2006-06-16 21:24:16.000000000 +0000 @@ -986,9 +986,10 @@ if (/^Received:\s/) { push @{$self->{TRACE}}, substr($_, 10) } elsif (/^From /) { $self->{FROM} = $_ } else { - my $idx = index $_, ": "; - $key = substr $_, 0, $idx; - $value = $idx != -1 ? substr $_, $idx + 2 : ""; + ($key = $_) =~ s/^(.+?):.*/$1/; # key = what comes before 1st ':' + s/^.+?://, s/^\s+//, s/\s+$//; # value = what comes after w/o + $value = $_; # leading, trailing whitespace + if ($decode eq 'ALL' || $decode eq 'HEADER') { use MIME::Words qw(:all); $value = decode_mimewords($value);
Write a response