#!/bin/sh
#
# $OpenBSD: new_voice,v 1.2 2014/08/27 06:58:00 ajacoutot Exp $

extension="wav"
contenttype="audio/x-wav"

fn=$1
tempfn=/tmp/voice.temp

email=root

seperator="========== $$fn =========="

echo To: $email > $tempfn
echo From: ${email}@`hostname` >> $tempfn
echo Subject: Voicemail: `/bin/date +%Y-%m-%d` - `/bin/date +%Hh%M` >> $tempfn
echo Mime-Version: 1.0 >> $tempfn
echo Content-Type: multipart/mixed\; boundary=\"$seperator\" >> $tempfn
echo "" >> $tempfn

pagefn=voice.$$.$extension

outputfn=$fn.$extension

/usr/local/bin/rmdtopvf $fn | /usr/local/bin/pvftowav 2>/dev/null > $outputfn

echo --$seperator >> $tempfn
echo Content-Type: application/octet-stream; name=\"$pagefn\" >> $tempfn
echo Content-Type: $contenttype\; name=\"$pagefn\" >> $tempfn
echo Content-Transfer-Encoding: base64 >> $tempfn
echo Content-Disposition: attachment\; filename=\"$pagefn\" >> $tempfn
echo "" >> $tempfn
cat $outputfn | openssl base64 >> $tempfn

rm -f $outputfn

echo --$seperator >> $tempfn

/usr/sbin/sendmail < $tempfn $email
rm -f $tempfn
rm -f $1
