How to convert voicemail emails

by labmin on December 4, 2010

My work upgraded our phones to the Droids! Unfortunately the Droid could not play our company voicemails from our PBX. So I wrote this script to intercept the voicemail emails, convert the wav file to an mp3 and then forward the voicemail to the original user.


export EMAIL='PBX <pbx>'

cd /mail/drop/new

for i in $( ls ); do

  cd mail/drop/new

  # This removes system generated emails
  axBad=$( cat $i | grep X-Original-To: | sed 's/...............\(.*\)/\1/'  )
  if [ "$axBad" == "root" ]; then
     rm -f /zxa/mail/drop/new/$i
    # Grab the to and from address
    axto=$( cat $i | grep "To: \"\"" $i | sed 's/........\(.*\)/\1/' | sed 's/\(.*\)................./\1/')
    axfrom=$( cat $i | grep From: | sed 's/.............\(.*\)/\1/' | sed 's/\(.*\)./\1/' )
    axsubject=$( cat $i | grep Subject: | sed 's/.........\(.*\)/\1/'  )
    axbody1=$( sed -n '30,30p'  $i )
    axbody2=$( sed -n '31,31p'  $i )
    axbody3=$( sed -n '32,32p'  $i )
    axbody4=$( sed -n '33,33p'  $i )
    axbody5=$( sed -n '34,34p'  $i )
    axbody6=$( sed -n '35,35p'  $i )
    echo $axbody1 > /etc/postfix/vmail/proc/body.txt
    echo $axbody2 >> /etc/postfix/vmail/proc/body.txt
    echo $axbody3 >> /etc/postfix/vmail/proc/body.txt
    echo $axbody4 >> /etc/postfix/vmail/proc/body.txt
    echo $axbody5 >> /etc/postfix/vmail/proc/body.txt
    echo $axbody6 >> /etc/postfix/vmail/proc/body.txt
    #Strip the wav file from the eml file
    uudeview -i -p /etc/postfix/vmail/proc +e .wav /mail/drop/new/$i > /dev/null 2>&1 

    # Convert the wav file to mp3
    /usr/local/bin/ffmpeg -i /etc/postfix/vmail/proc/msg0001.WAV -ab 8k /etc/postfix/vmail/proc/msg0001.mp3 > /dev/null 2>&1 

    #send the new email out
    cd /etc/postfix/vmail/proc
    mutt -n -s "$axsubject" -a msg0001.mp3   -- "$"  < body.txt

#clean up directory
rm -rf /etc/postfix/vmail/proc/*.*
rm -f /mail/drop/new/$i


Leave your comment


Required. Not published.

If you have one.