#!/bin/csh -f # This script sets up a basic spam filtering scheme using procmail. # The .procmailrc script is commented so the user can figure out # what's going on. # daw, 3/5/04 switch (`uname -s``uname -r`) case SunOS5*: breaksw default: exec echo ${0}: does not run on `uname -s` `uname -r` endsw while($#argv) switch ("$1") case -d: set DEBUG # shift # breaksw # fall through to verbose case -v: set VERBOSE shift breaksw default: set DQ = '"' exec echo ${0}: "What do I do with $DQ$1$DQ?" endsw end cd if ($?VERBOSE) echo `date +%T` Checking for existing files set EXISTS foreach FILE ( .forward .procmailrc mail ) if (-d $FILE && $FILE == "mail") continue if (-e $FILE) set EXISTS = ( $EXISTS $FILE ) end if ("$EXISTS" != "") then if ($#EXISTS > 1) then echo The files $EXISTS already exist in ~ /usr/ucb/echo -n "I need to rewrite these files. Shall I rename them and proceed? " else echo The file $EXISTS already exists in ~ /usr/ucb/echo -n "I need to rewrite this file. Shall I rename it and proceed? " endif set INPUT = $< set INPUT = `echo "$INPUT" | tr "[A-Z]" "[a-z]"` switch ("$INPUT") case n: case no: exec echo "[Not confirmed]" breaksw case y: case ye: case yes: breaksw default: exec echo ' Type "yes" to confirm' breaksw endsw if ($?VERBOSE) echo `date +%T` "Renaming file(s)" set TSTMP = `date +%y%m%d` foreach FILE ( $EXISTS ) if (-e $FILE.$TSTMP) set TSTMP = `date +%y%m%d.%H%M` end foreach FILE ( $EXISTS ) echo " $FILE => $FILE.$TSTMP" /bin/mv $FILE $FILE.$TSTMP end endif if (! -e "mail") then if ($?VERBOSE) echo `date +%T` Setting up mail directory mkdir mail chmod 700 mail endif if ($?VERBOSE) echo `date +%T` Setting up .procmailrc set ME = `/usr/ucb/whoami` cat >> .procmailrc <> .forward <