#!/usr/local/bin/perl # May need to change if your Perl is elsewhere # # Filter - scans incoming messages and places thim into the appropriate # mail folder based upon your specifications. NOTE: this is a quick # program for demonstration purposes only, no claim is made to whether # this program will work for you or not!!!! # # place in your .forward file: # "| /u2/home/bt/mail/filter" # or where ever you place this file # $MAIL = "/u2/home/bt/mail"; # Directory for all specialty files $DEFMAIL = "/usr/spool/mail/bt"; # Default mail file # # Get the From, Subject and To fields. $header = 0; $input = ; while (length($input) != 1) { @headerarray[$header++] = $input; if (($cmd, $param, $etc) = ($input =~ /^(\S+)\s+(\S+)\s*(.*)/)) { if ($cmd eq "From:") { $from = $param; } elsif ($cmd eq "Subject:") { $subjectline = $param . " " . $etc; } elsif ($cmd eq "To:") { $to = $param; } } $input = ; } # lowercase the fields for easier checking: $to =~ tr/A-Z/a-z/; # determine what folder to dump the mail into. REPLACE WITH YOUR OWN INFO! $mailfile = "$DEFMAIL"; if ($to eq "turbo-list@cpac.washington.edu") { $mailfile = "$MAIL/turbo.mail";} elsif ($from eq "bt@cpac.washington.edu") { $mailfile = "$MAIL/bt.mail"; } # etc.. . # dump the info into the mailfile: open(MAILFILE, ">> $mailfile"); foreach (0..$header-1) { print MAILFILE @headerarray[$_]; } print MAILFILE "\n"; # a blank line as a seperator 'tween header and body while (! eof(STDIN) ) { $input = ; print MAILFILE $input; } print MAILFILE "\n"; # a blank line as a seperator to next message close(MAILFILE); exit(0);