home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / infoserv / gopher / Unix / GopherTools / saveassubject < prev    next >
Encoding:
Text File  |  1994-01-30  |  884 b   |  60 lines

  1. #!/usr/local/bin/perl
  2.  
  3. if ($#ARGV != 0) {
  4.     print "Usage: $0 <directory name>\n";
  5.     exit;
  6. }
  7.  
  8. chdir @ARGV[0];
  9.  
  10. open(tmphead, "+>/tmp/headers$$");
  11.  
  12. $HeaderFlag = 1;
  13.  
  14. while (<STDIN>) {
  15.     #
  16.     # Get rid of Headers we don't want
  17.     #
  18.     if ((/^Received:/)||
  19.     (/^Message-Id:/)||
  20.     (/^Cc:/)) {
  21.     next;
  22.     }
  23.  
  24.     if (/^Subject:/) {
  25.     $SubjectLine = $_;
  26.     $SubjectLine =~ s/^Subject: //;
  27.     }
  28.  
  29.     if ((/^$/) && ($HeaderFlag == 1)) {
  30.     # End of headers
  31.  
  32.     open(Outfile, ">$SubjectLine");
  33.     $HeaderFlag = 0;
  34.  
  35.     seek(tmphead, 0,0);
  36.     while (<tmphead>) {
  37.         if ((/^Date:/)     || (/^From:/) ||
  38.         (/^Subject:/)  || (/^Keywords:/)||
  39.         (/^Location:/) || (/^ACategory/)) {
  40.  
  41.         print Outfile;
  42.         }
  43.     }
  44.     close(tmphead);
  45.     unlink "/tmp/headers$$";
  46.     }
  47.     
  48.     # Filter out the header lines
  49.     
  50.     if ($HeaderFlag == 1) {    
  51.     print tmphead;
  52.     }
  53.     else {
  54.     print Outfile;
  55.     }
  56.     
  57. }
  58.     
  59.  
  60. close Outfile;