#!/bin/tcsh

#Mail processor 
#This is called when mail comes in.  First argument must be the username
#that the mail is addressed to.
#Use wrapper.c if you need this to be setuid

setenv DIR /home/ghio/alpha
setenv HOSTNAME "alpha.c2.org"

#Make sure other users can't read the nymserver's files
umask 077

if ( $1 == alias ) then
 wait:
 if ( -r $DIR/pid ) then
  sleep 60
  goto wait
  #Maybe a shlock would be better?
 endif
 echo $$>$DIR/pid
 cat >$DIR/in-raw-msg
 cd $DIR
 if (-r in-dec-msg) then
  rm in-dec-msg
 endif
 ./pgpext <in-raw-msg in-pgp-msg
 rm in-raw-msg
 setenv PGPPASS pgppw
 /usr/local/bin/pgp +batchmode +force in-pgp-msg -o in-dec-msg >& pgpout
 unsetenv PGPPASS
 #rm in-pgp-msg
 if (-r in-dec-msg) then
  $DIR/doalias in-dec-msg
 endif
 rm $DIR/pid
else
 if ( $1 == help || $1 == info || $1 == remailer-help || $1 == remailer-info ) then
  cat >$DIR/temp$$
  /usr/lib/sendmail `$DIR/getfrom <$DIR/temp$$` <$DIR/nymhelp
  rm $DIR/temp$$
 else
  if ( $1 == used || $1 == sendused ) then
   cat >$DIR/temp$$
   (echo "Subject: Used addresses on $HOSTNAME";echo "";\
    ls $DIR/nyms|awk -F. '{print $1}'|uniq)\
    |/usr/lib/sendmail -f nobody@$HOSTNAME `$DIR/getfrom <$DIR/temp$$`
   rm $DIR/temp$$
  else
   echo $1 >>$DIR/log
   echo "Received: by $HOSTNAME for $1@$HOSTNAME" >$DIR/temp$$
   /bin/echo -n " " >>$DIR/temp$$
   cat >>$DIR/temp$$
   cat $DIR/temp$$ >$DIR/in.queue/`date +%S%M%j%H`$$
   rm $DIR/temp$$
  endif
 endif
endif
