Migrating Windows Mobile to Android

Windows to Android SMS conversionToday was the day I finally broke free from the shackles of Windows Mobile 6.5 on my HTC HD2 (brilliant device, merely decent OS), loading a ROM for Android 2.3 (Gingerbread). I’ll go into details another time, but the only major obstacle for me was transferring SMSes. After much Googling, it was still not obvious how to do it, but I can now confirm it is possible. Here’s how I did it (short version):

It’s the middle step, the conversion, that is unintuitive. Surely there should be a PIM Backup app for Android? Or an app that imports PIM Backup files? As far as I can tell, there’s not, but this post by the SMS Backup & Restore creator Ritesh Sahu set me on the right track. He created a WinMo app called SMS Exporter, but there were mixed reports of success, so I followed his advice and read through this post by Mario instead.

Mario had written a Perl script to convert the PIM Backup format (semicolon-separated values) to a format compatible with SMS Backup & Restore (XML) such that the converted file could be ‘restored’ on the new Android OS.

Unfortunately I (and other users) couldn’t get his script to work properly, and I don’t know Perl, and he wasn’t replying in the comments, but looking at the code I figured it couldn’t be too hard to recreate in Python. Neither format is terribly complicated after all; each is effectively just a row of attributes for each message.

You can check out and download my Windows Mobile to Android SMS Converter tool from this site. To use it, you just need to have Python 2.x installed (you may have already – type “python” without quotes in your command prompt or terminal), and to perform the conversion, set the working directory to that of the Python script and use the command python pim2smsbr.py backup_file [output_file], where:

  • backup_file refers to the name of your PIM Backup file, something like PIMBackup_20110701.pib (if you created it on the date of this post), and
  • [output_file] is an optional argument that allows you to specify a filename for the output (or you can omit it, and it will output alongside the input file).

The final step is simply copying the output file onto your Android device, opening SMS Backup & Restore, choosing Restore, and selecting the output file (and choosing not to check for duplicates). And then you’re done, congratulations! It should import all the messages rather quickly and they are automatically associated with existing contacts and built into conversation threads.

So that’s it! It’s a ugly, hacky three-step process, but it’s very possible. Enjoy your superior operating system with your data intact :). Let me know of any trouble you have in the comments and I’ll get back to you ASAP.

23 thoughts on “Migrating Windows Mobile to Android

  1. Hi Pie,

    First of all thanks for your effort! I’ve tried running your script after many failed attempts with the PERL version. I get the script to run, but I get the following error:

    Reading input from PIMBackup_20110706.pib…
    Processing SMS messages…
    Traceback (most recent call last):
    File “pim2smsbr.py”, line 113, in
    convert(args.source[0], args.out)
    File “pim2smsbr.py”, line 58, in convert
    msg_xml = process(row)
    File “pim2smsbr.py”, line 78, in process
    date = int(time.mktime(time.strptime(row[16], “%Y,%m,%d,%H,%M,%
    File “C:\Python27\lib\_strptime.py”, line 454, in _strptime_time
    return _strptime(data_string, format)[0]
    File “C:\Python27\lib\_strptime.py”, line 325, in _strptime
    (data_string, format))
    ValueError: time data ” does not match format ‘%Y,%m,%d,%H,%M,%S’

    Is there any way you could help me with this?


    • G’day Tjado,

      Absolutely I can help; that’s what I’m here for ;). Naturally my script hasn’t been through a lot of testing, since I only have my own backup to test against, so problems are not unexpected.

      This one looks pretty straightforward though – it looks like you have a backed up entry without a time value, which therefore can’t be converted. I’ve added a check for that case which will simply set the date to zero, so you can try again if you like, and hopefully it goes through! I suspect it will lead to another error though.

      If all else fails and you trust me enough to send me your backup file (promise I won’t read it to closely!), I can guarantee to work around any issues more efficiently than via the comments :).

      Good luck!

  2. Hello there,

    Thanks for simplifying all these, much appreciated!

    However, everytime i try executing the command, i keep getting a SyntaxError: invalid syntax message.

    Is there a specific place i muct place your script or my PIM .pib file?

    Thanks in advance!

    • Hi Jeremy,

      My pleasure :). I live to serve.

      That said, I’m not sure where the syntax error is coming from… That sounds like a problem with the code rather than the input. Can you let me know what your input is though, and what the rest of the error says (especially line numbers)?

      And for the record (and others), there is no specific places you need to put things, you just need to provide the correct paths. For example, if you downloaded the script to your desktop, and had your .pib file in a folder called “pim_files”, then you could invoke the script one of two ways:

      Absolute paths:
      python C:\Users\Jeremy\Desktop\pim2smsbr.py C:\Users\Jeremy\Desktop\pim_files\backup.pib

      Relative paths:
      Open the command prompt, navigate to your desktop, and then simply type:
      python pim2smsbr.py pim_files\backup.pib

      • Hi,

        Thanks for the useful tools. Shame I am too hamfisted to use them!

        I have the PIMBackup_20110727.pib and pim2smsbr.py stored on my desktop.

        I’ve got python 2.7.2 installed and used the command prompt “c:\users\J4nup>” to enter:

        c:\users\J4nup>python C:\Users\J4nup\Desktop\pim2smsbr.py C:\Users\J4nup\Desktop\PIMBackup_20110727.pib

        I got the the error ‘python’ is not recognized as an internal or external command.

        What am I doing wrong?

        • Hi there J4nup,

          That error you’re getting is not uncommon. What it’s saying is that you need to add Python to your system path, as detailed at http://docs.python.org/faq/windows.html, or more concisely in the first three paragraphs at http://www.imladris.com/Scripts/PythonForWindows.html. It’s not too difficult a process (in short, add “;C:\Python27” without quotes to the PATH value), and afterwards you should be able to run Python scripts from the command line.

          Then you can just use relative paths to run the script. Open the command prompt, type “cd Desktop” [enter] to change directory to your desktop, then you can just use “python pim2smsbr.py PIMBackup_20110727.pib“.

          Let me know if that does/doesn’t help!

          • Hi,

            I’m still not having any joy, could it be that I’m using the wrong version of python for vista? I couldn’t get the instructions on: http://www.imladris.com/Scripts/PythonForWindows.html to work.

            Re: The My Computer, Properties. System information; Advanced tab, Environment Variables etc

            These options do not show when right-clicking on My Computer.

            When in c:\users\j4nup\>(I typed)cd c:\python27
            getting into:
            c:\python27>(I typed)python (to return)
            Python 2.7.2 (default, jun 12 2011, 15:08:59) [MSC v.1500 32 bit (intel)] on win32 Type “help”,”copyright”, “credits”, or license for more information

            What do I do at that point? I tried a few of the variations from:
            >>>cd desktop (Returned: File “”), line 1 cd desktop syntaxerror: incorrect syntax

            >>>python pim2smsbr.py PIMBackup_20110727.pib
            (Also returned: File “”), line 1 python pim2smsbr.py PIMBackup_20110727.pib syntaxerror: incorrect syntax)

            I hope that is enough detail, cheers in advance.


          • Hi again,

            Regarding environment variables, probably the easiest way to get to them is to click the start menu and type “environment” into the search field (just click Start and type, basically), and choose the first result, “Choose environment variables for your account”. Vista may be slightly different to 7. To do it manually, right click My Computer, go to Properties, then choose Advanced System Settings (on the left), then click the Environment Variables button.

            If nothing works, don’t worry! You can just refer to Python manually, as you have discovered. Simply go to your desktop as before, but instead of just typing “python pim2smsbr PIMBackup_20110727.pib”, type “C:\Python27\python pim2smsbr PIMBackup_20110727.pib”. This will give Windows an absolute path to Python, so it doesn’t need to worry about any environment variables. You don’t actually want to run the Python interpreter as you did before.

            THAT should hopefully work :). Good luck, and keep me posted!

          • Hello,

            Again cheers for all your assistance.

            Feels like I am getting there, slowly!

            When doing:
            c:\users\j4nup>C:\Python27\python pim2smsbr PIMBackup_20110727.pib

            I got the error message:
            “Can’t open file ‘pim2smsbr.py; [Errno 2] No such file or directory.

            Tried the same with “pim2smsbr” same error, the 2 files are saved on my desktop.

            Copied and pasted them (pim2smsbr.py & PIMBackup_20110727.pib) both to the c:\python27 directory as well but same result.


          • Remember to change directory to your desktop first with “cd Desktop\”! Otherwise it will look for the script in the working directory, C:\Users\j4nup. Alternatively prefix both arguments with “Desktop\”.

          • Getting closer…

            – Reading input from ‘PIMBackup_20110727.pib…

            Error: Couldn’t load messages file, please check your input path and contents.

          • Excellent! I’m not entirely sure what the primary cause of that error is. I suspect you either didn’t check the box to back up your SMSes in PIM Backup (unlikely), or you chose to do a binary (compressed) backup rather than a text backup.

            This tool only works with the text backup option, so if that’s the case you could try it again with the text backup option chosen. Otherwise, you can always send me your backup file (promise I won’t snoop!) and I’ll sort it out for you.

  3. Hi there,

    I am about to pull my hair out. I am having the exact same issue as J4nup. Going on over 2 hours now. I honestly at this point would like to send you my file. How should I contact you, or will you contact me?

    Many thanks for your time and help.

  4. Progress, but no success. It is critical that you add it to your environment like you mentioned. I missed that part. Now I get this result:

    Microsoft Windows [Version 6.1.7600]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Stephen>cd desktop

    C:\Users\Stephen\Desktop>python pim2smsbr.py PIMBackup_20110802.pib [output]
    PIM Backup to SMS Backup & Restore Converter
    Written by Oliver Lade (piemaster21@gmail.com)
    More information at http://piemaster.net/tools/winmo-android-sms-converter/
    Questions and comments very welcome!

    – Reading input from ‘PIMBackup_20110802.pib’…
    – Processing SMS messages
    – Working…
    Traceback (most recent call last):
    File “pim2smsbr.py”, line 192, in
    convert(args.source[0], args.out)
    File “pim2smsbr.py”, line 118, in convert
    msg_xml = process(row)
    File “pim2smsbr.py”, line 165, in process
    address = row[18].split(‘;’)[2].strip(‘\\’)
    IndexError: list index out of range

  5. SB,

    Not glad to see you’re having trouble, but glad I’m not alone.

    I got as far as you but am encountering a unicode decode error now. Rather than your Index error.

    Let me know how you get on.

  6. Hey J4nup,

    I skimmed your post which got me to this point. Hopefully Pie can get some time and respond to us. Honestly I’m about to send him my file at this point. I’ve got nothing “top secret” on it; it’s all sentimental. Appreciate the help Pie. Thanks.

    • Hi guys! I’m here! Really! I’m just extremely busy, and will look into your errors as soon as possible.

      At present I can’t help you with decoding errors unless you give me the strings that can’t be decoded, since everything seems to work fine on my machine but breaks for others.

      Regarding uncaught Python errors (such as the IndexError above), I should be able to deal with those easily enough.

      Given all the feedback, I’m considering kicking the forums into action, but that takes effort too. Time! Keep the bug reports coming though, I’ll get back to you ASAP :). If you need direct contact (e.g. to send attachment), click Contact at the top.

  7. Hi,
    Just want to say a HUGE thanks for your effort creating this python script.
    I have just let go (hooray!) of my “trusty” old ipaq914c WM6.1 and have fought all day trying to find a tool to yank SMS from the WM – It is , pardon my french, unbe-fåggin-lieveable that Redmond can’t supply a tool to do that (Here’s hoping for WP7+8+!?). But hey – You could… !

    But one word of advice :) you might have saved me *some* time trying to figure out what was wrong with your script, because it refused to unzip the .csm file from the .pib file.
    Until I saw the “further notice” about DOING THE PIMBackup in “not binary”. :)

    But anyway – your python DID work – it extracted +800 SMS’es in 0.82 secs !! (Thought it failed, but it DID go that fast :D )

    Now going on to trying the restore on the Android.

    Kudos to you !!

    • Hi Brian,
      Excellent to hear that it worked! I can’t blame M$ for not doing it themselves though; it’s not really in their nature to give you all your data in an Android-readable format.

      I pushed an update yesterday that will hopefully fix all the problems decoding non-standard characters. The “not binary” thing has caught a few people, and I’ve been meaning to rewrite this information page for some time to make it all a bit more intuitive. There’s just so many points of possible failure, since it’s quite a low-level process, so it’s difficult to write up concisely.

      What I’d like to do is write my own app to do all the heavy lifting for you, but it would probably be done on the WinMo side, which I know nothing about coding for. Oh well. Whatever works for now!

  8. Hi,
    I tried several times to run the script but without success. I read the forum and no one have the problem that I have. The script run “reading input from pim…, then error and “input file not found at pim…, aborting.
    I checked the backup and is not binary or compressed. I make it rar to open it to be sure and I found the csm file and it was 39kb.
    Have you get any ideas for my problem?

    Thanks in advance

    • Hi John, “input not found at …” suggests that you’re inputting the incorrect path to your PIM file and so the script can’t locate it. Could you list the exact file path of the PIM file, and the exact input that you are entering?

  9. Hi,
    It all looks simple, but I can’t run pim2sms script at any way. Tried to run windows command prompt and start script – not working, tried to run python command prompt from win command prompt and run pim2sms script – not working, tried to run python.exe directly from C:/Python25/python.exe – works but can’t start pim2sms script at any way. Can anybody please write exactly what is needed at command prompt? I’m doing it llike this:
    running python.exe
    then I write:
    python pim2smsbr.py PIM.pib
    and nothing is happenig!
    File “”, line 1
    python pim2smsbr.py PIM.pib
    SyntaxError: invalid syntax – appears!
    My pim2smsbr.py and PIM.pib files are located just in case in two directories; Desktop and C:/Python25
    Shoul I use ” ” or or something else? How to run this stubborn script?

    • Hi Jack, sorry for the massive delay! Sadly it’s not as easy as just specifying a command for you, since it depends on your working directory and system path. To be sure, you can move your PIM.pib file into C:\Python25, then open command prompt and type cd C:\Python25. Now everything is in the same directory and you should be okay to type exactly:
      python pim2smsbr.py PIM.pib
      If that fails, then it’s my fault, not yours. Hopefully it won’t though!

Leave a Reply