SMS Server Tools 3
This site is hosted by Kekekasvi.com
 Menu
Basic information:
Additional information:
Support:
Get SMS Server Tools 3:
Additional Options

 Sponsored links

 Search
Custom Search

 Visitor locations
 
 SMS Server Tools 3 Community
Welcome, Guest. Please login or register. Thu May 23, 2024 02:18
SMSTools3 Community » Help and support Bottom

[answered] help with a script requared

  This topic is locked

Page:  1

Author Post
Member
Registered:
Jul 2010
Location: Moscow, Russian Federation
Operating system name and version: Fedora 12
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
 
 
'bash' Syntax Highlight powered by GeSHi


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!

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Your script looks pretty good ;).

I have not tested it, but with a quick view it may have troubles with handling of headers in email. In many cases there is Content-Type: text/plain; charset=..., but in some cases it may be like "Content-Type: text/plain; charset="us-ascii"; Format="flowed"". Some awk '{print $1;}' may help for this. But multipart/MIME messages are different thing, and much more difficult to handle. Perhaps some external mail library could be used for those.

The idea looks good. Any message is converted to UTF-8, and this should work if $from is detected. Then, if message can be converted to ISO, it can be sent using the GSM alphabet. In other cases UCS2 is used.

I do not know why message written in russian does not work. Perhaps $from value is not detected, or it is unknown for iconv. A value of $from should be printed to the file and then iconv --list will show if the value is supported.

In any case, echo "русский текст" | iconv -t ISO-8859-15 will not work, because of those russian characters. But this should not be a problem in the script.

The original script sendsms tries to change the ownerchip of the file if necessary. This however works only when the script is executed by the root. When a mail system is executing the script, chmod 666 could be used instead of chown.

Have you seen this topic: email2sms-ucs: international version of email2sms. It's written by edo and contains a perl script for similar purposes than your script. I have not used that script, but at least it seems that MIME issues are handled.

Member
Registered:
Jul 2010
Location: Moscow, Russian Federation
Topic owner
OK, I saw that script but forgot about it before starting to write my own. After a bit of modification it serves my needs pretty well. At least it works. Thanks goes to edo and as usual to keke. Kiitos, Keijo!

_______________
:q!

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Perhaps you could show or explain what kind of modifications you did? If you post answer to that topic, edo will get notified and may discuss about modifications. Other users may also appreciate the information.

  This topic is locked

Page:  1

SMSTools3 Community » Help and support Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.