#!/bin/sh

# This script can be used with procmail to build an "email to sms" gateway.
# Simply put the destination number in the subject field and the text in the
# email body. Then pipe the email through this script. If smsd is running,
# it will send the sms.

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

INFILE=$(mktemp /var/tmp/smsgw.in.XXXXXX) || exit 1
OUTFILE=$(mktemp /var/tmp/smsgw.out.XXXXXX) || exit 1
tee $INFILE | formail -X "From:" -X "Subject:" | sed -e "s/^Subject:/To:/" > $OUTFILE
cat $INFILE | formail -I "" >> $OUTFILE
rm $INFILE
mv $OUTFILE /var/spool/sms/outgoing
echo "SMS queued"
