Home > Android, Apple, Hardware, iPhone > iPhone to Android SMS Converstion Script

iPhone to Android SMS Converstion Script

As promised here’s a copy of my iPhone to Android script. Just a quick and dirty python script that reads in a backup from itunes and converts it to a bit of XML able to be read in by SMS Backup and Restore on the android platform

from sqlite3 import *
from sqlite3 import *
from xml.sax.saxutils import escape
import codecs
import re
f = codecs.open('sms.xml','w','utf-8')
f.write ('''< ?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<smses>
''')
# This is 31bb7ba8914766d4ba40d6dfb6113c8b614be442.mddata or 31bb7ba8914766d4ba40d6dfb6113c8b614be442.mdbackup usally
c = connect('sms.db')
curs = c.cursor()
curs.execute('''SELECT address,date,text,flags FROM message WHERE flags &lt;5 ORDER BY date asc''')
for row in curs:
        a= escape(unicode(row[0]))
        d = escape(unicode(row[1]))
        t = row[3]-1
        t = str(t)
        b = re.sub('"',"'",escape(unicode(row[2])))
 
        f.write( '<sms protocol="0" address="'+a+'" date="'+d+'000" type="'+t+'" subject="null" body="'+b+'" toa="0" sc_toa="0" service_center="null" read="1" status="-1" />'+"\n")
f.write(
'''</smses>''' )
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • StumbleUpon
  • TwitThis
  • Print
  1. Roberto
    July 8th, 2010 at 09:17 | #1

    hello,

    I have an iPhone and I wanted to convert every single SMS in an eml file (then i import this eml into Gmail via IMAP, so I have all text messages on gmail). Could you help me create a script to do this?

    thanks and congratulations for the blog!

  1. No trackbacks yet.