Mail to SMS forwarding using phone number as email subject

This script allows you easily forward email messages to SMS, using phone number as email subject.

SHELL=/bin/sh
VERBOSE=OFF
MAILDIR=/mnt/flash/spool/maildir
DEFAULT=/mnt/flash/spool/mail/mails
LOGFILE=/var/log/procmail.log

:0
*  ^Subject:.*
{
:0c:
${DEFAULT}
:0
{
#bW:mail.body.lock
SUBJ_=`formail -xSubject: \
      | expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g' | sed -r 's/[+]+//g'`
#POSI=`expr index "${SUBJ_}" 00`
REPLA0=$SUBJ_
POSI=`expr substr $REPLA0 1 2`
LUN=`expr length $REPLA0`
#if [[ $POSI == "00" ]]; then
#       SUBJ_=`expr substr $REPLA0 3 $LUN`
#fi
    # Get the body of the message into a variable
    # Accept only the first five lines
    # Discard newlines, i.e. put everything on one line
    BODY_=`sed -e '1,/^$/ d' | head -5 | tr -d '\n'`
#echo "${SUBJ_} ${BODY_}" > /var/test.txt
#| /etc/sms/scripts/email2sms
}
:0:bW:mail.body.lock
| case $POSI in 00) SUBJ_=`expr substr $REPLA0 3 $LUN`;; *) REPLA0=$SUBJ;; esac; OUTFILE=$(mktemp /mnt/flash/spool/outgoing/smsgw.out.XXXXXX);echo "From:mail\nTo:${SUBJ_}\n\n${BODY_}" > $OUTFILE
}