So you got a shiny new iPhone to replace your aging Palm. You spend a day or two copying your addressbook. Or perhaps you sync to M$ Outlook and back. But what about the SMS/MMS messages? Should you abandon them? Well, you really have little choice

I did not want to giveup on my 64,000 or so SMS messages in my Treo, and a few more thousand in my other iPhone, so I decided to write a utility to import SMSs into the iPhone. In fact three utilities resulted. They use a common XML representation of SMS messages as an intermediate format, referred to as mXML from now on. There is no simple way to AUGMENT an existing iPhone SMS database, so instead you must take your existing one, convert it to mXML, and then, together with PalmOS's mXML feel it into the xml2sql script.

iPhoneImport.c is a C application that takes one or more PalmOS Message databases (get them from your Treo/Centro device RAM - a file called "Messages Database" or "Messages Database.pdb") and outputs a mXML file that contains all the messages in it.

sql2xml.rb is a ruby script that will take the SQL dump of iPnone SMS datbaase and exports an mXML file with these messages.

xml2sql.rb is a ruby script that will take one or more mXML files and output SQL to create a valid iPhone SMS database.

The basic usage looks like this in my case[Linux] (two treos and two iphones import into one iphone). The lines preceeded by a # are comments

#install needed tools
sudo apt-get install ruby sqlite3 gcc
#compile iPhoneImport
gcc -o iPhoneImport iPhoneImport.c
#get the first iPhone's current sms database
scp root@10.0.0.190:/var/mobile/Library/SMS/sms.db iphone1.db
#get the second iPhone's current sms database
scp root@10.0.0.192:/var/mobile/Library/SMS/sms.db iphone2.db
#copy the first Treo's SMS database from my local copy
cp ~/Treo1_backup/Messages\ Database.pdb Treo1.pdb
#copy the second Treo's SMS database from my local copy
cp ~/Treo2_backup/Messages\ Database.pdb Treo2.pdb
#convert the treo databases into an mXML file
./iPhoneImport Treo1.pdb Treo2.pdb > treos.xml
#convert the first iPhone's database into an mXML file
sqlite3 iphone1.db ".dump" | ruby sql2xml.rb > iphone1.xml
#convert the second iPhone's database into an mXML file
sqlite3 iphone2.db ".dump" | ruby sql2xml.rb > iphone2.xml
#merge the xml files and store into iPhone format
rm sms.db && ruby xml2sql.rb treos.xml iphone1.xml iphone2.xml | sqlite3 sms.db
#send to the first iPhone (compress using bzip for x-fer speed)
cat sms.db | bzip2 -9 | \
   ssh root@10.0.0.190 "cd /var/mobile/Library/SMS/ && bunzip2 > sms.db && chown mobile:mobile sms.db"
#all done

The files can be downloaded here. This code is by no means complete or good - just functional. The C code does not free any memory, and the ruby code is definitely not optimized for speed. Also some code can error out in conditions that I did not test (for example the code must decide what country a phone number belongs to, and the list in the app is not complete, but it is easy to add more there). To avoid anyone using all the research that went into this being misused, this code is GPLv3 licensed.

© 2012-2017