# A little mail script to use an editor.
if (!$?argv) then exit
if ($argc < 2) then
  secho "mailr <userlist>"
  exit 1
endif
shift 1 argv

if ($?subject) then unset subject
input -p "Subject: " -n subject

set tmp = /usr/tmp/MM_$user
chmod og-rwx $tmp > $tmp
if ($$?EDITOR) then $$EDITOR $tmp
else jove $tmp

if (!(-e $tmp) || -z $tmp) then
  secho "mailr: Empty message... nothing mailed."
  if (-e $tmp) then rm $tmp
  exit
endif

input -p "Append signature file [Y/n]? " -c ch
if ($ch !~ "[nN]") then (secho "Yes" ; cat ~/.sig >> $tmp)
else secho "No"

secho -n "Mailing..."

if ($?subject) then (mail -s "$subject" $argv < $tmp)
else (mail $argv < $tmp)

secho "done!"

if (-e $tmp) then rm $tmp
