1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#!/bin/bash
# This script converts a received sms file into a html file.
if [ $# -ne 1 ]; then
echo "Usage: sms2html filename"
exit 1
fi
if grep "Alphabet:.*UCS" $1 >/dev/null; then
ucs2="true"
else
ucs2="false"
fi
# Write HTML header
echo "<html><body>"
# Write Header of the SMS file
echo "<b>"
while read line; do
if [ -z "$line" ]; then
break
else
echo "$line<br>"
fi
done < $1
echo "</b>"
# Write message text
echo "<p>"
if [ "$ucs2" = "true" ]; then
text=`od -t x1 $1 | cut -c8-99`
position="first"
foundstart="false"
previous=""
for character in $text; do
# Search for the start of the 16 bit part. Starts after "0a 0a"
if [ "$foundstart" = "false" ]; then
if [ "$character" = "0a" ] && [ "$previous" = "0a" ]; then
foundstart="true"
fi
else
# Combine two bytes to one 16bit character in html syntax
if [ "$position" = "first" ]; then
echo -en "&#x$character"
position="second"
else
echo -en "$character;"
position="first"
fi
fi
previous="$character"
done
else
text=`formail -I "" < $1`
echo "$text"
fi
# Write HTML footer
echo ""
echo "</body></html>"
|