home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / alt / cesium / 1 next >
Encoding:
Internet Message Format  |  1992-09-15  |  5.4 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!think.com!cayman!colin
  2. From: colin@Cayman.COM (Colin "Atilla" Steele)
  3. Newsgroups: alt.zines
  4. Subject: Re: crossover, samizdat generally
  5. Message-ID: <COLIN.92Sep15104228@caicos.Cayman.COM>
  6. Date: 15 Sep 92 14:42:28 GMT
  7. References: <1992Sep12.233138.17905@maths.tcd.ie> <18u750INNlj5@agate.berkeley.edu>
  8. Sender: news@cayman.COM
  9. Organization: Cayman Systems Inc., Cambridge, MA
  10. Lines: 181
  11. Nntp-Posting-Host: caicos
  12. In-reply-to: jaffray@sunkist.berkeley.edu's message of 13 Sep 92 01:56:48 GMT
  13.  
  14.  
  15. Here's a small piece of what you're looking for.  It's a perl-based
  16. mail filter that can be used to file mail in appropriate "piles".  If
  17. you need additional explaination on how to use it, how to set up
  18. filters, just drop me a line.
  19.  
  20. cut here ----------------------------------------------------------------------
  21. #!/bin/perl
  22. # Replace the previous line with the path to perl
  23. # on your machine.
  24. #         
  25. ###############################################################################
  26. # FILEMAIL.PL
  27. # Author:  Colin A. Steele (colin@Cayman.com)
  28. # Tue Sep 15 09:56:08 EDT 1992
  29. # Redistribute freely.  Go nuts ;-)
  30. # Report bugs to colin@Cayman.com.  I may not fix it, but I'll be sympathetic.
  31. #     
  32. # Usage:  filemail.pl [-d] [-p] [-l]
  33. # use -d for debugging messages.
  34. # use -p to print input to stdout.
  35. # use -l to make filemail.pl log what it does.
  36. ###############################################################################
  37. require "getopts.pl";
  38.  
  39. #
  40. # Check command line options
  41. # -d for debug, -p for print the input to stdout, -l for logging
  42. #
  43. &Getopts('dlp');
  44. $DEBUG = $opt_d;
  45. $PRINT = $opt_p;
  46. $LOG = $opt_l;
  47.  
  48. #
  49. # Set up default variables.
  50. #
  51. ($DEBUG) && (print "Setting up default variables.\n\n");
  52. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
  53. $mon++;
  54. $today = "$mon_$mday_$year";
  55. $inheader = 0;
  56. $header = "";
  57. ($to,$cc,$bcc,$from,$subject) = ();
  58. $outFile = "/home/caicos/colin/Mail/unread-mail";
  59. $logFile = "/home/caicos/colin/Mail/filemail.log";
  60. $opened = 0;
  61. $logopened = 0;
  62.  
  63. while(<>){
  64.   # Unix mail format
  65.   if (/^From \S*\s*... ... .. ..:..:.. ....$/) {
  66.     ($DEBUG) && (print "Unix mail format\n");
  67.     ($DEBUG) && (print "Collecting header...");
  68.     $inheader = 1;
  69.   }
  70.   # Babyl format
  71.   if (/^\037\014$/) {
  72.     ($DEBUG) && (print "Babyl mail format\n");
  73.     ($DEBUG) && (print "Collecting header...");
  74.     $inheader = 1;
  75.   }
  76.   
  77.   if (/^$/) {
  78.     $inheader = 0;
  79.     ($DEBUG) && (print "\n");
  80.   }
  81.   
  82.   #
  83.   # While in the header, collect it up.
  84.   #
  85.   if($inheader){
  86.     $header .= $_;
  87.     ($DEBUG) && (print "...");
  88.   }
  89.  
  90.   #
  91.   # Then, if not in the header, and a header has been collected,
  92.   # set the to, cc, bcc, etc. variables.
  93.   #
  94.   elsif($header){
  95.     ($hdr = $header) =~ s/,(\n|\s)+/,/g;
  96.     
  97.     $to = $1 if $hdr =~ /\nTo: (.*)\n/; 
  98.     $cc = $1 if $hdr =~ /\nCc: (.*)\n/; 
  99.     $bcc = $1 if $hdr =~ /\nBcc: (.*)\n/; 
  100.     $from = $1 if $hdr =~ /\nFrom: (.*)\n/; 
  101.     $subject = $1 if $hdr =~ /\nSubject: (.*)\n/;
  102.  
  103.     if ($DEBUG) {
  104.       print "To: $to\n";
  105.       print "CC: $cc\n";
  106.       print "BCC: $bcc\n";
  107.       print "From: $from\n";
  108.       print "Sub: $subject\n";
  109.     }
  110.  
  111.     ############
  112.     # Here's the actual filtering part.  Set the outfile based on
  113.     # what we've gleaned in the header of the message.
  114.     ############
  115.     # Filter one:  if it's to support... (no commas in to field)
  116.     if ($to !~ /,/ && $to =~ /(^|\W+)support@Cayman.COM(\W+|$)/) {
  117.       $outFile = "/home/caicos/colin/Mail/unread-support-mail";
  118.     }
  119.     # Filter 1a:  if it's to support... (no commas in to field)
  120.     if ($to !~ /,/ && $to =~ /(^|\W+)support@cayman.Cayman.COM(\W+|$)/) {
  121.       $outFile = "/home/caicos/colin/Mail/unread-support-mail";
  122.     }
  123.     # Filter 2:  if it's from bart...
  124.     if ($from !~ /,/ && $from =~ /(^|\W+)bart(\W+|$)/) {
  125.       $outFile = "/home/caicos/colin/Mail/unread-bart-mail";
  126.     }
  127.  
  128.     #
  129.     # Logging
  130.     #
  131.     if ($LOG) {
  132.       (&DEBUG) && (print "Logging message\n");
  133.       open(LOG, ">>$logFile") && ($logopened = 1);
  134.       ($logopened) && (print LOG "***\n$today\t$from\t$Sub\n$outFile\n***\n");
  135.     }
  136.     
  137.     #
  138.     # Open up the output file(s).
  139.     #
  140.         (print "File:  $outFile\n") if $DEBUG;
  141.         (print "File2: $outFile2\n") if $DEBUG;
  142.     $opened = 0;
  143.     $opened2 = 0;
  144.     $opened = 1 if open(FP, ">>$outFile");
  145.         if ($DEBUG && !$opened) {
  146.                 print "Couldn't open $outFile\n";
  147.         }
  148.     if($outFile2) {
  149.       $opened2 = 1 if open(FP2, ">>$outFile2");
  150.             if ($DEBUG && !$opened2) {
  151.                     print "Couldn't open $outFile2\n";
  152.             }
  153.     }
  154.         
  155.  
  156.     #
  157.     # Print the header to stdout, and if an output file has been
  158.     # opened, also print the header to that file.
  159.     #
  160.     ($PRINT) && (print "$header\n");
  161.     (print FP "$header\n") if $opened;
  162.     (print FP2 "$header\n") if $opened2;
  163.     
  164.     #
  165.     # Since we've collected and printed out the header:
  166.     # Reset the header variable and the to, cc, etc. variables.
  167.     #
  168.     $header = "";
  169.     ($to,$cc,$bcc,$from,$subject) = ();
  170.   }
  171.  
  172.   #
  173.   # Once the header has been taken care of, print following lines to stdout,
  174.   # and if an output file has been opened, also print the line to that file.
  175.   #
  176.   else {
  177.     ($PRINT) && (print);
  178.     (print FP) if $opened;
  179.     (print FP2) if $opened2;
  180.   }
  181. }
  182.  
  183. #
  184. # Clean up.
  185. #
  186. close(FP) if $opened;
  187. close(FP2) if $opened2;
  188.  
  189. --
  190.  
  191.  
  192. ------------------------------------------------------------------------------
  193.  Colin Steele     | Cayman Systems, 26 Landsdowne St., Cambridge, MA 02139
  194.  colin@cayman.com | (617) 494-1916 x209 | applelink D0523 | Fax (617) 494-9270
  195.