Mass SMS

Boris Samorodov bsam at ipt.ru
Thu Jun 1 12:21:27 PDT 2006


On Thu, 01 Jun 2006 23:13:56 +0400 Boris Samorodov wrote:

>   command = /usr/local/bin/mail2sms.py 

> The last script is at the attachement. It uses a Subject field as a

Hm, here it is:

#!/usr/local/bin/python
# $Id: mail2sms.py 6 2005-06-17 19:30:56Z bsam $

from email.Header import decode_header

import codecs
import email
import time
import sys

dir = '/var/spool/sms'

lines = ''

while 1:
  try:
    line = raw_input()
  except EOFError:
    break

  lines += line.rstrip() + '\n'

msg = email.message_from_string(lines)

to = email.Utils.parseaddr(msg['To'])[1]

f = open(dir + '/db/' + 'phones', 'rb')
while 1:
  try: 
    line = f.readline()
  except EOFError:
    print 'Matching not found, exiting!'
    sys.exit()

  if not line:
    print 'Matching not found, exiting!'
    sys.exit()

  if line[0] in ('#'):
    continue

  line = line.strip()
  if line in (''):
    continue
  phone, who = line.split('\t')
  if who == to:
    break

subj_full = decode_header(msg['Subject'])

enc = subj_full[0][1]
if not enc:
  enc = 'koi8-r'
subj = unicode(subj_full[0][0], enc).encode('utf-16')

priority = 'Z'
smsnum = str(time.time())

fname = 'OUT' + priority + '_' + phone + '_' + smsnum + '.txt'
fname = dir + '/outbox/' + fname

file = open(fname, 'wb')
file.write(subj)
file.close()

file = open(dir + '/source/' + smsnum, 'wb')
file.write(lines)
file.close()


WBR
-- 
Boris B. Samorodov, Research Engineer
InPharmTech Co,     http://www.ipt.ru
Telephone & Internet Service Provider


More information about the freebsd-isp mailing list