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

Selec All Code:
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>''' )
This entry was posted in Android, Apple, Hardware, iPhone and tagged , , , . Bookmark the permalink.

One Response to iPhone to Android SMS Converstion Script

  1. Roberto says:

    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!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">