(dired-do-redisplay, dired-maybe-insert-subdir): Change interactive
[bpt/emacs.git] / lib-src / b2m.pl
index 6ec923d..38eb96e 100644 (file)
@@ -30,7 +30,7 @@ use Mail::Address;
 use Date::Parse;
 
 my($whoami) = basename $0;
-my($version) = '$Revision: 1.4 $';
+my($version) = '$Revision: 1.5 $';
 my($usage) = "Usage: $whoami [--help] [--version] [--[no]full-headers] [Babyl-file]
 \tBy default, full headers are printed.\n";
 
@@ -62,7 +62,7 @@ if (<> !~ /^BABYL OPTIONS:/) {
 
 while (<>) {
     my($msg_num) = $. - 1;
-    my($labels, $full_header, $header);
+    my($labels, $pruned, $full_header, $header);
     my($from_line, $from_addr);
     my($time);
 
@@ -79,7 +79,11 @@ while (<>) {
     }
     $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+//) {
@@ -91,23 +95,25 @@ while (<>) {
        $_ = '';
     }
 
-    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
     $labels =~ s/[,\s]+/, /g;
-    
+
     foreach my $rmail_header qw(summary-line x-coding-system) {
        $full_header =~ s/(^|\n)$rmail_header:.*\n/$1/i;
     }
@@ -117,7 +123,7 @@ while (<>) {
     }
     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;
@@ -146,3 +152,5 @@ while (<>) {
 }
 
 close(STDOUT) || die "$whoami: Error closing stdout: $!\n";
+
+# arch-tag: 8c7c8ab0-721c-46d7-ba3e-139801240aa8