Skip to content

Instantly share code, notes, and snippets.

@x-magic
Created November 19, 2016 06:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x-magic/90cdecee4ffe940839cac1024e8ae02b to your computer and use it in GitHub Desktop.
Save x-magic/90cdecee4ffe940839cac1024e8ae02b 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 <xmagic5589@gmail.com>
# With contribution from: Artur Bodera <abodera@gmail.com>
#
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
@alonsosaez1501
Copy link

You have complete script? Grettings from chile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment