#!/usr/bin/python # # Converter for SMSs # backed up on Symbian by MsgExport # to be restored on Android by SMS Backup & Restore # # 1/ On Symbian use MsgExport app (from tinyhack.com), select TXT format # 2/ Transfer resulting txt file (SmsByDate is enough) from Nokia (if you # have SD card from its \SMSLOG, if not, from memory \DATA\SMSLOG) # 3/ Convert file on any machine with python (did not test on windows, though): # ./MsgExport2SMSBackupRestore.py < SmsByDate2010-01-18.txt > sms-20100118.xml # 4/ Transfer resulting xml file to Android SD card to /SMSBackupRestore dir # 5/ On Android use SMS Backup & Restore app to restore SMS-es from this xml # # Note: MsgExport CSV format is not usable, it mixes received and sent SMSs. # # contact Piotr Kucharski for bugfixes (provide input .txt) import sys import re import time TEL = re.compile('.*\((?P\+*[0-9]*)\)') DAY = re.compile('(?P[0-9]+)(st|nd|rd|th)') txt = [] splittel = False type = None SMS_RECV = 1 SMS_SENT = 2 def Sms(type, tel, date, txt): body = '%s' % ' '.join(txt) # poor man's xml quoting body = body.replace('&', '&').replace('"', '"') body = body.replace('>', '>').replace('<', '<') print(' ') # header print(""" """) for line in sys.stdin.readlines(): line = line.strip() # small workaround for contacts with an embedded newline # (we just search for tel in next line) if splittel: m = TEL.match(line) if m: tel = m.group('tel') splittel = False continue if line.startswith('To: ') or line.startswith('From: '): if txt: Sms(type, tel, date, txt) # and start over txt = [] tel = None date = None if line.startswith('From: '): type = SMS_RECV elif line.startswith('To: '): type = SMS_SENT m = TEL.match(line) if m: tel = m.group('tel') else: splittel = True continue # ignore empty lines if not line: continue # ignore garbage from begin of file if not type: continue if line.startswith('Date: '): # stupid "th" # 6th May 2009 3:52:29 pm day, date = line[6:].split(' ', 1) m = DAY.match(day) if m: day = m.group('num') date = '%s %s' % (day, date) date = int(time.mktime((time.strptime(date, "%d %B %Y %I:%M:%S %p")))) continue # Android has no concept of folders, all SMSs are threaded by number if line.startswith('Folder:'): folder = True continue if folder: # this line contains folder name folder = False continue # it seems like it is always one line, but hey. txt.append(line) if txt: Sms(type, tel, date, txt) print("")