Version of smsd: smstools-3.1.8-1.fc14.i686
Smsd installed from: package repository (test repository for F14)
Name and model of a modem: Huawei Technologies Co., Ltd. E620 USB Modem
Interface: USB
Hi! I'm writing a script that will handle incoming mail and place it in smstools outgoing directory (lets call it email2sms). The purpose of this script is correct handling of russian characters in sms. Namely, I would like to write messages in russian more than 70 characters long. The second problem is different encoding of incoming mail. I.e. some messages are in utf-8, others are in koi8-r. This script should take care of it. So, here it is:
#!/bin/bash
OUTFILE1=$(mktemp /tmp/letter.XXXXXX)
OUTFILE2=$(mktemp /tmp/body.XXXXXX)
cat >$OUTFILE1
from=$(grep "Content-Type: text/plain; charset=" $OUTFILE1 | sed 's/Content-Type: text\/plain; charset=//g')
cat $OUTFILE1 | iconv -f $from -t UTF-8 | sed '1,/^$/ d' | sed '/^$/d' > $OUTFILE2
# the above lines extract body of incoming email and recode it to utf-8
destination=$(whoami)
# username is <phone_number>@<host>
TEXT=$(cat $OUTFILE2)
ALPHABET=""
if ! echo -n "$TEXT" | iconv -t ISO-8859-15 >/dev/null 2>&1; then
ALPHABET="Alphabet: UCS"
fi
#if we can convert text to iso-8859, then no problem
smsd_user="smsd"
owner=""
if [ -f /etc/passwd ]; then
if grep $smsd_user: /etc/passwd >/dev/null; then
owner=$smsd_user
fi
fi
# the above is from keke' universal script; probably I don't need this construction
TMPFILE=`mktemp /tmp/smsd_XXXXXX`
echo "To: $destination" >> $TMPFILE
[ -n "$ALPHABET" ] && echo "$ALPHABET" >> $TMPFILE
echo "" >> $TMPFILE
if [ -z "$ALPHABET" ]; then
echo -n "$TEXT" >> $TMPFILE
else
echo -n "$TEXT" | iconv -t UNICODEBIG >> $TMPFILE
fi
if [ "x$owner" != x ]; then
chown $owner $TMPFILE
fi
FILE=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $TMPFILE $FILE
OUTFILE1=$(mktemp /tmp/letter.XXXXXX)
OUTFILE2=$(mktemp /tmp/body.XXXXXX)
cat >$OUTFILE1
from=$(grep "Content-Type: text/plain; charset=" $OUTFILE1 | sed 's/Content-Type: text\/plain; charset=//g')
cat $OUTFILE1 | iconv -f $from -t UTF-8 | sed '1,/^$/ d' | sed '/^$/d' > $OUTFILE2
# the above lines extract body of incoming email and recode it to utf-8
destination=$(whoami)
# username is <phone_number>@<host>
TEXT=$(cat $OUTFILE2)
ALPHABET=""
if ! echo -n "$TEXT" | iconv -t ISO-8859-15 >/dev/null 2>&1; then
ALPHABET="Alphabet: UCS"
fi
#if we can convert text to iso-8859, then no problem
smsd_user="smsd"
owner=""
if [ -f /etc/passwd ]; then
if grep $smsd_user: /etc/passwd >/dev/null; then
owner=$smsd_user
fi
fi
# the above is from keke' universal script; probably I don't need this construction
TMPFILE=`mktemp /tmp/smsd_XXXXXX`
echo "To: $destination" >> $TMPFILE
[ -n "$ALPHABET" ] && echo "$ALPHABET" >> $TMPFILE
echo "" >> $TMPFILE
if [ -z "$ALPHABET" ]; then
echo -n "$TEXT" >> $TMPFILE
else
echo -n "$TEXT" | iconv -t UNICODEBIG >> $TMPFILE
fi
if [ "x$owner" != x ]; then
chown $owner $TMPFILE
fi
FILE=`mktemp /var/spool/sms/outgoing/send_XXXXXX`
mv $TMPFILE $FILE
I know, it looks now as a promising nomination for silly scripting award. So any help is appreciated (hints, thoughts, etc.). Currently it doesn't work partially. When incoming mail is written in latin letters only the script places correct file in outgoing directory. However if the mail is writen in russian, then there's an error in procmail log:
And the resulting file in outgoing directory looks as follows:
See, there's empty line in the place where message text should be. And Alphabet shouldn't be UCS for this message.
The mentioned above iconv-error from log can be produced in terminal window. Here's an example:
My local is UTF-8:
Encoding of tmp file ($OUTFILE1) in the script is:
So, why it all doesn't work I don't know. However I'm able to send message manually, using the script keke provided in this post.
Any thoughts?
_______________
:q!