#!/bin/csh
# ~/bin/.csh/mailto.comp		by	Julian H. Stacey
# For comments see mailto.holz
# There is a link from ~/bin/mailto.comp > .csh/mailto.comp 
# as firefox does not know to look for new apps in dirs beginning with a dot.

set tmp_dir=~/mail/drafts
set name=$$	# pid
set file=$tmp_dir/$name
# If I am unlucky with a low PID this could smash other existing drafts !
set log=~/.mail.outgoing.log
mkdir -p $tmp_dir		>& /dev/null
touch				$file		# create if not existant
if ( $1.x == ".x" ) then	#{
		true # do nothing
	else	# }{
		echo "To: $1" | sed -e s/mailto://		 >> $file
	endif	# }
cat ~/mail/components | grep -v "To:"	>> $file	# cat in case pre-exists
# Later perhaps I should use comp command.
xterm						\
	-n mailto 				\
	-T "`hostname` - Mailto" 		\
	-g 80x40 				\
	-e /usr/bin/vi $file

echo ""							>> $log
echo "START {"							>> $log
echo "Date: `date -u +%Y-%m-%dT%H:%M:%SZ`"			>> $log
# if ( "`filesize 0 == $file`.x" == .x) then #{
#  echo "~/bin/.csh/mailto.comp: Abandoning $file `ls -l $file`" 	>> $log
#  cat $file							>> $log
#  echo "STOP }"							>> $log
#  rm $file
#  exit 1
# else	# }{
#  echo "~/bin/.csh/mailto.comp: Sending $file `ls -l $file`"	>> $log
#  sendmail -i -t < $file
#  cat $file							>> $log
#  echo "STOP }"							>> $log
#  rm $file
#  exit 0
# endif	# }

echo "~/bin/.csh/mailto.comp: Sending $file `ls -l $file`"	>> $log
sendmail -i -t < $file
cat $file							>> $log
echo "STOP }"							>> $log
rm $file
