#!/bin/csh -f
# Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
# 
# Permission to use, copy, modify, and distribute this material 
# for any purpose and without fee is hereby granted, provided 
# that the above copyright notice and this permission notice 
# appear in all copies, and that the name of Bellcore not be 
# used in advertising or publicity pertaining to this 
# material without the specific, prior written permission 
# of an authorized representative of Bellcore.  BELLCORE 
# MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
# OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
#

echo -n "To: "
set to = $<
echo -n "Subject: "
set subject = $<
echo -n "CC: "
set cc = $<

record:
echo -n Press RETURN when you are ready to start recording:
set foo = $<

set fname = /tmp/audio-out.$$
set fnameraw = /tmp/audio-raw.$$

echo "To: " "$to" > $fname
echo "Subject: " "$subject" >> $fname
echo "CC: " "$cc" >> $fname
echo "MIME-Version: RFC-XXXX" >> $fname
echo "Content-Type: audio/basic" >> $fname
echo "Content-Transfer-Encoding: base64" >> $fname
echo  "" >> $fname
echo "Speak into the microphone.  When you are done, wait 2 or 3 seconds and then press CONTROL-C."
stty intr 
onintr foobar
cat  < /dev/audio > $fnameraw
foobar:
mmencode -b < $fnameraw >> $fname
rm $fnameraw
echo "" >> $fname

whatnext:
echo ""
echo "What do you want to do?"
echo ""
echo "1 -- Send mail"
echo "2 -- Listen to recorded message"
echo "3 -- Replace with a new recording"
echo "4 -- Quit"
set which = $<
    switch ($which)
        case 1:
          echo -n "Sending mail, please wait...  "
          /usr/lib/sendmail $to  $cc < $fname
          if (! $status) then
            echo "Done."
            rm $fname
            exit
          else
            echo Mail delivery failed, draft mail is in $fname
          endif
          breaksw
        case 2:
          metamail -d $fname
          breaksw
        case 3:
          goto record
        case 4:
          exit
    endsw
goto whatnext
