#!/bin/sh

VOICE_DIR=/var/spool/voice
BINDIR=/usr/bin

FLAG=$VOICE_DIR/incoming/.flag

# This script is called when a message was recorded. 
# It gets the following argument:
#      $1 : filename of the recorded message

# set the flag, this will cause vgetty to turn on the message light
touch $FLAG

#
# Below are some suggestions on ways to use this shell script
#

PATH=/bin:/usr/bin:/usr/local/bin:$BINDIR:/usr/local/bin/mh

MAIL=/usr/lib/sendmail
MAILTO=root
N=`basename "$1"`
TMP=/tmp/`basename $0`.$$

## Notify user by mail that a message has arrived
#
#(
#	echo "Subject: Voice call: $N"
#	echo
#	echo zplay -s "$1"
#) | $MAIL $MAILTO

## convert message to SUN .au, uuencode and mail it
## This could be useful if you have a fast mail connection.
#
#(
#	echo "Subject: Voice message"
#	echo$
#	adpcmtopvf <"$1" | pvftoau -ulaw | uuencode "$N".au
#) | $MAIL $MAILTO

##
## MIME format thanks to Marc Evans <marc@Synergytics.Com>
##

## mail an audio/basic file via metamail, works only for adpcm
## Use this method if you have /dev/audio support
#adpcmtopvf <"$1" | pvfspeed 1.2 | pvftobasic >$TMP
#metasend -t $MAILTO -b -z -s "Voice-mail message" -e base64 \
#         -m audio/basic -f $TMP </dev/null 2>&1 >/dev/null
#rm -f $TMP

## The following section defines new MIME audio formats, they
## will be played on the modem. Use this if you don't have /dev/audio.
##
##  Add the following lines (less the comment characters) to /etc/mailcap:
##   audio/x-adpcm-3; zplay -s %s ; description="ADPCM 3-bit encoded audio"
##   audio/x-adpcm-2; zplay -s %s ; description="ADPCM 2-bit encoded audio"
##   audio/x-celp; zplay -s %s ; description="CELP encoded audio"
##  OR, add the following lines to your ~/.mh_profile (if you use mhn):
##   mhn-show-audio/x-adpcm-3; zplay -s %f
##   mhn-show-audio/x-adpcm-2; zplay -s %f
##   mhn-show-audio/x-celp; zplay -s %f
##
## NOTE: There are many variations on the above lines. Choose what is right
## for your particular configuration and needs.

## set FORMAT to "adpcm-2", "adpcm-3" or "celp", as appropiate.
FORMAT=adpcm-3

## Send the message via MIME mail (using mh as the agent)
#umask 077
#( echo "To: $MAILTO"
#  echo "Subject: Voice-mail"
#  echo "--------"
#  echo "# audio/x-$FORMAT [ Voice-mail message ] $1"
#) >$TMP
#echo 'send' | comp -use -editor /usr/local/bin/mh/mhn -file $TMP >/dev/null
#rm -f $TMP

## Alternative method (using metamail directly)
#metasend -t $MAILTO -b -z -s "Voice-mail message" -e base64 \
#         -m audio/x-$FORMAT -f "$1" </dev/null 2>&1 >/dev/null
