#!/bin/csh
#mail-out	put mail into a spool file
#with locking.

#Change this to the program to run.
set PROG = "/your-mixmaster-directory/mixmaster -R"

# Change this to the incoming mail spool directory.
cd /your-reorder-directory/reorder

#Max number of messages at one time before spam alert
@ spamthresh = 20

#If manually clearing bypass spam alert
if( $1 == "clear") then
   \rm -f working
   \rm -f none
   @ spamthresh = 20000
endif

if (-e working) exit
if (-e none) exit
echo "" > working
echo "" > lock
sleep 10
mv in*  outgoing/
echo "" > none
\rm -f lock

# SPAM detector
set num = `\ls outgoing`
if( $#num > $spamthresh) then
   /usr/bin/mail -s "SPAM ALERT!" middle-man-admin < /dev/null
   exit
endif
# End SPAM detector

foreach joe (outgoing/in*)
   cat $joe | premail -decode | $PROG >>& log
   \rm -f $joe
end
\rm -f working
