*** hypermail-2b29/contrib/hypetombox.pl	Sat Oct  9 22:18:01 1999
--- hypermail-2b29-new/contrib/hypetombox.pl	Sun Sep 24 20:48:26 2000
***************
*** 11,26 ****
  #     With modifications by Kent Landfield (kent@landfield.com). 
  #     Further modifications by Peter McCluskey (pcm@rahul.net).
  #     If it's broke, it's my fault.
  #
  # Usage:
  #
! #   hypetombox.pl [-d <directory>] [-m <output_filename>]
  #
  # $Header: /cvs/hypermail/hypermail/contrib/hypetombox.pl,v 1.3 1999/10/10 05:18:01 kent Exp $
  
  require 5.000;
  use Getopt::Std;
! getopts('d:m:');
  
  # This is a list of the fields in the comment header of each message.
  
--- 11,36 ----
  #     With modifications by Kent Landfield (kent@landfield.com). 
  #     Further modifications by Peter McCluskey (pcm@rahul.net).
  #     If it's broke, it's my fault.
+ #     A few more mods by Fyodor (fyodor@insecure.org) [9/24/00]:
+ #        * Reinitialize "header_count" to zero for each message (bugfix)
+ #        * Added -H (additional header) option (useful for filtering messages)
+ #        * Added -t ("To: " field) option
+ #        * Extended the date formats accepted in "Received:" headers
+ #        * Added 'a' option to append to mailbox rather than clobbering it
+ #        * Updated usage info
  #
  # Usage:
  #
! #   hypetombox.pl [-a] [-H <header(s) to add to each msg] [-d <directory>] [-t <toemailaddy>] [-m <output_filename>]
! #   -a means append to mailbox instead of clobbering it
! #   -H adds the header(s) you specify.  If more than one, put the three
! #      characters %0A between them.
  #
  # $Header: /cvs/hypermail/hypermail/contrib/hypetombox.pl,v 1.3 1999/10/10 05:18:01 kent Exp $
  
  require 5.000;
  use Getopt::Std;
! getopts('ad:H:m:t:');
  
  # This is a list of the fields in the comment header of each message.
  
***************
*** 37,43 ****
  
  $mbox_name = $opt_m || 'mbox';
  
! (open MBOX, ">$mbox_name") || die "can't open $mbox_name";
  
  # Loop on the input files.
  
--- 47,64 ----
  
  $mbox_name = $opt_m || 'mbox';
  
! if ($opt_H) {
! 	$opt_H =~ s/%0A/\n/g;
!         chomp($opt_H);
! 	$opt_H .= "\n";
! }
! 
! if ($opt_a) {
! 	$openflag = ">>";
! } else {
! 	$openflag = ">";
! }
! (open MBOX, "$openflag$mbox_name") || die "can't open $mbox_name";
  
  # Loop on the input files.
  
***************
*** 56,62 ****
      # Loop on lines in the file
  
      $state = 'HeaderComments';
! 
      my $line;
  
      while($line = <M>) {
--- 77,83 ----
      # Loop on lines in the file
  
      $state = 'HeaderComments';
!     $header_count = 0;
      my $line;
  
      while($line = <M>) {
***************
*** 83,89 ****
  		elsif($received =~ /^(\d{1,2} \w{3} {1,2}\d{2,4} \d{2}:\d{2}:\d{2} \w{3})/)
  		{
  		    $date = $1;
! 		}
                  else {
                      $date = 'Bogus date';
                      $boguscntr += 1;
--- 104,112 ----
  		elsif($received =~ /^(\d{1,2} \w{3} {1,2}\d{2,4} \d{2}:\d{2}:\d{2} \w{3})/)
  		{
  		    $date = $1;
! 		} elsif($received =~ /^(\w{3}), (\d{1,2}) (\w{3}) (\d{4}) (\d{2}:\d{2}:\d{2})/) {
!                      $date = sprintf("%s %s %.2d %s %s", $1, $3, $2, $5, $4);
!                 }
                  else {
                      $date = 'Bogus date';
                      $boguscntr += 1;
***************
*** 92,100 ****
                  print MBOX "From $email  $date\n";
                  print MBOX "Date: $sent\n";
  		print MBOX "Message-Id: <$id>\n";
! 		print MBOX "To: bogus\n";
  		print MBOX "From: $email ($name)\n";
  		print MBOX "Subject: $subject\n";
                  if ($inreplyto) {
  		    print MBOX "In-Reply-To: <$inreplyto>\n";
  		}
--- 115,126 ----
                  print MBOX "From $email  $date\n";
                  print MBOX "Date: $sent\n";
  		print MBOX "Message-Id: <$id>\n";
! 		print MBOX "To: " . (($opt_t)? $opt_t : "bogus") ."\n";
  		print MBOX "From: $email ($name)\n";
  		print MBOX "Subject: $subject\n";
+ 		if ($opt_H) {
+                   print MBOX $opt_H;
+                 }
                  if ($inreplyto) {
  		    print MBOX "In-Reply-To: <$inreplyto>\n";
  		}
