#!/bin/tcsh

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

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
setenv NYM `./getnym <in-dec-msg`
if ($NYM != "") then
#If the nym doesn't have an accout create one with null password
if (! -r nyms/$NYM.password) then
echo >nyms/$NYM.password
endif
./processmsg <in-dec-msg nyms/$NYM.password nyms/$NYM.replyblock $NYM outfile
if (-s outfile) then
/usr/lib/sendmail -odq -oem -f $NYM@$HOSTNAME -t <outfile
endif

#Remove nyms with null passwords
if ("`cat nyms/$NYM.password`" == "") then 
if (-r nyms/$NYM.password) then
rm nyms/$NYM.password
endif
if (-r nyms/$NYM.replyblock) then
rm nyms/$NYM.replyblock
endif
else
echo "From: alias@$HOSTNAME" >confirm
echo "To: $NYM@$HOSTNAME" >>confirm
echo "" >>confirm
echo "This is to inform you that your message to alias@$HOSTNAME" >>confirm
echo "regarding $NYM@$HOSTNAME was processed successfully." >>confirm
/usr/lib/sendmail -odq -f alias@$HOSTNAME $NYM\@$HOSTNAME <confirm
rm confirm
endif
endif
endif
