Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save svoboda-jan/c73681f941790896b27e5bd28806bf22 to your computer and use it in GitHub Desktop.
Save svoboda-jan/c73681f941790896b27e5bd28806bf22 to your computer and use it in GitHub Desktop.
SMS Server Tools 3 event handler script (mainly used for converting messages to UTF-8 encoding, for example, those messages with CJK characters included)
#!/bin/bash
#
# This script processes events from smsd.
# It mainly will converts SMS encoded with UCS2 encoding to UTF-8 format expected by many other applications.
# To use it, edit your /etc/smsd.conf and add the following line:
#
# eventhandler = /path/to/smstools-eventhandler.sh
#
# When a new message is received in /var/spool/incoming/, message files with following header line will be converted:
#
# Alphabet: UCS2
#
# Download SMS tools from http://smstools3.kekekasvi.com/
# Latest version of this script at https://gist.github.com/x-magic/90cdecee4ffe940839cac1024e8ae02b
# Author: Bill Gong <[email protected]>
# With contribution from: Artur Bodera <[email protected]>
#
case $1 in
SENT)
# TODO: Action when message is confirmed sent
;;
RECEIVED)
# When received a message, convert to UTF-8 encoding if required
if sed -e '/^$/ q' < "$2" | grep "^Alphabet: UCS2" > /dev/null; then
TMPFILE=`mktemp /tmp/smsd_XXXXXX`
sed -e '/^$/ q' < "$2" | sed -e 's/Alphabet: UCS2/Alphabet: UTF-8/g' > $TMPFILE
sed -e '1,/^$/ d' < $2 | iconv -f UNICODEBIG -t UTF-8 >> $TMPFILE
mv -f $TMPFILE $2
fi
;;
FAILED)
# TODO: Action when failed to send message
;;
REPORT)
# TODO: Not exactly sure what is this
;;
CALL)
# TODO: Action when received a call (why is this not working?)
;;
*)
# When unknown status is received, terminate the script with exit code 1
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment