#!/bin/sh
# This is an example how to use an eventhandler with smsd.
# $1 is the type of the event wich can be SENT, RECEIVED, FAILED or REPORT.
# $2 is the filename of the sms.


#The following lines report an event to the console
echo smsd reports an event:
echo type: $1
echo file: $2


#The next line changes the file attributes so that everybody can read
#received SM
if [ "$1" = "RECEIVED" ]; then
  chmod a+r $2
fi


#This sends all received SM to an email receiver:
if [ "$1" = "RECEIVED" ]; then
  cat $2 | /usr/sbin/sendmail root@localhost;
fi


#This forwards all received SM to another mobile phone:
if [ "$1" = "RECEIVED" ]; then
  FROM=`formail -zx From: <$2`
  formail -f -I "To: 491722056395" <$2 >$2.forward
  echo "from $FROM" >> $2.forward
  mv $2.forward /var/spool/sms/outgoing
fi

