use Date::Parse;
my($whoami) = basename $0;
-my($version) = '$Revision: 1.4 $';
+my($version) = '$Revision: 1.3 $';
my($usage) = "Usage: $whoami [--help] [--version] [--[no]full-headers] [Babyl-file]
\tBy default, full headers are printed.\n";
while (<>) {
my($msg_num) = $. - 1;
- my($labels, $full_header, $header);
+ my($labels, $pruned, $full_header, $header);
my($from_line, $from_addr);
my($time);
}
$labels = $1;
- s/(?:((?:.+\n)+)\n+)?\*\*\* EOOH \*\*\*\n+// || goto malformatted;
+ # Strip the integer indicating whether the header is pruned
+ $labels =~ s/^(\d+)[,\s]*//;
+ $pruned = $1;
+
+ s/(?:((?:.+\n)+)\n*)?\*\*\* EOOH \*\*\*\n+// || goto malformatted;
$full_header = $1;
if (s/((?:.+\n)+)\n+//) {
$_ = '';
}
- if (! $full_header) {
+ # "$pruned eq '0'" is different from "! $pruned". We want to make
+ # sure that we found a valid label line which explicitly indicated
+ # that the header was not pruned.
+ if ((! $full_header) || ($pruned eq '0')) {
$full_header = $header;
}
- # End message with a single newline
- s/\s+$/\n/;
+ # End message with two newlines (some mbox parsers require a blank
+ # line before the next "From " line).
+ s/\s+$/\n\n/;
# Quote "^From "
s/(^|\n)From /$1>From /g;
- # Strip the integer indicating whether the header is pruned
- $labels =~ s/^\d+[,\s]*//;
# Strip extra commas and whitespace from the end
$labels =~ s/[,\s]+$//;
# Now collapse extra commas and whitespace in the remaining label string
}
else {
foreach my $addr_header qw(return-path from really-from sender) {
- if ($full_header =~ /(?:^|\n)$addr_header:\s*((?:\S.*\n)+)/i) {
+ if ($full_header =~ /(?:^|\n)$addr_header:\s*(.*\n(?:\B.*\n)*)/i) {
my($addr) = Mail::Address->parse($1);
$from_addr = $addr->address($addr);
last;