#!/bin/csh -f
set MIXDIR = ~/Mix
if ( ! -d $MIXDIR ) then
	echo Didn\'t find $MIXDIR
	exit
endif
set MIXMASTER = $MIXDIR/mixmaster
set MIXLIST = $MIXDIR/type2.list
set NMASTERS = `wc -l < $MIXLIST`
set MAX = 4 # $NMASTERS # A random list of remailers (of length MAX)
								# is created for each recipient.
set FILE ; set TO ; set SUBJECT
if ( $#argv != 4 || $4 != - ) then
	echo -n Send this message via mixmaster remailers\?\ \[n\]\ 
	if ( $< != y ) exit
endif
if ( $#argv == 0 ) clear
if ( $1 == "" ) then
	while ( $FILE == "" )
		echo -n File:\ ; set FILE = $<
	end
else
	set FILE = $1
endif
if ( $2 == "" ) then
	while ( "$TO" == "" )
		echo -n To:\ ; set TO = $<
	end
else
	set  TO = $2
endif
if ( "$3" == "" ) then
	while ( "$SUBJECT" == "" )
		echo -n Subject:\ ; set SUBJECT = $<
	end
else
	set SUBJECT = "$3"
endif
if ( $#argv == 4 && $4 == - ) goto SKIPMENU
set ANS = t
while ( $ANS == t || $ANS == s || $ANS == f )
	clear
	echo File:\ $FILE 
	echo To:\ $TO
	echo Subject:\ $SUBJECT
	echo If these values are correct, hit \<return\> to send the message.
	echo -n Enter f, t, or s to change a field, X to exit without sending.
	set ANS = $<
	switch ($ANS)
		case X:
			exit
		case f:
			echo -n File:\ ; set FILE = $<
			breaksw
		case t:
			echo -n To:\ ; set TO = $<
			breaksw
		case s:
			echo -n Subject:\ ; set SUBJECT = $<
			breaksw
		default:
			breaksw
	endsw
end
SKIPMENU:
set CWD = $cwd
cd $MIXDIR
if ( ! -e $FILE ) then
	if ( -e $CWD/$FILE ) then
		set FILE = $CWD/$FILE
	endif
endif
if ( $#argv != 4 || $4 != - ) echo -n Message sent to:\ 
foreach ADDRESS ( $TO )
	set ROUTE = `rnd $NMASTERS | cat -n | awk '{print $2" "$1}' | sort -n | head -$MAX | awk '{print $2}' | tr "\012" " "`
	$MIXMASTER $FILE -s "$SUBJECT" -to $ADDRESS -l $ROUTE
	if ( $#argv != 4 || $4 != - ) echo -n $ADDRESS\ 
end
if ( $#argv != 4 || $4 != - ) then
	echo " " ; echo -n Wipe and delete $FILE \?\ \[n\]\ 
	if ( $< == y ) pgp -w $FILE >& /dev/null
else
	pgp -w $FILE >& /dev/null
	endif
cd $CWD
