Recovering contacts in Windows Live Mail via harvesting your inbox

So you upgraded a machine from Vista or some such to Windows 7, and lost the email program as informed. You were wise and exported all of the emails and contacts beforehand. So you install Windows Live Mail and hurry through the import procedure. It looks good! Oh maybe you delete the backup, but just into the Recycle Bin.

Later you're tinkering around, deleting and moving files. It's not your machine and there's already so much trash in the bin, you wouldn't want your trash mixed with their trash (the horror!), so you empty yours. Whoops there went the backup, but all was imported perfectly so no worry.

Or was it! Actually the emails survived all right, only missing some images attached to a letter in the Drafts folder. Probably saved in a temporary location that wasn't preserved in the Windows 7 upgrade. The contacts though, are all horribly terribly wrong. Important people are missing! You were fooled into thinking a first and last name on your emails implied an association with their profile in your contacts, but alas it is not so!

Ah, but you are a programmer. Bahahaha!

So with time of the essence I coded up some quick and dirty Python.

Somewhat dumbed down harvest instructions

  1. First create the folder C:\Mail.
  2. In Windows Live Mail, press Alt+F for the File menu, then Export → Messages… → Microsoft Windows Live Mail
  3. Browse to C:\Mail, and complete the export, yes to All folders. Afterward you've a directory full of emails in .eml format.
  4. Download and install Python 2.6.4. Choose Windows x86 MSI Installer if you're not sure which. Install it to the default directory: C:\Python26
  5. Download this Python script (displayed above). Right click that download link and Save link as… C:\Mail\eml_to_csv.py
  6. Open a command prompt (Windows Key + R → cmd enter).
  7. In the console type:
    C:\Python26\python.exe C:\Mail\eml_to_csv.py C:\Mail C:\Mail\contacts.csv. After completion you now have a contacts file which can be imported.
  8. Back in Windows Live Mail in Contacts go Alt+F → Import → Comma Separated Values and select C:\Mail\contacts.csv
  9. You should see over a dozen separate mappings, First Name to First Name, Last Name to Last Name and so on, if you don't then stop here. If you do, click Finish! :)
  10. Purge any unwanted junk contacts! Use the information I put under Notes to determine the most recent email the contact was harvested from. Use these dates to your advantage to distinguish old/new addresses and so forth.

For troubleshooting/badasses

  1. After step 7 open the .csv file in Microsoft Excel.
  2. Choose Delimited, on the next page uncheck Tab and check Comma, then Finish.
  3. Use your awesome spreadsheet knowledge to sort (not the first line though!), fix, and purge your contacts. (Just FYI if you've no name with a contact I recommend clearing the Name field rather than placing the e-mail address here. Windows Live Mail will nicely distinguish these contacts as nameless then.)
  4. Upon completion use Save As… CSV (Comma delimited) and if asked if you want to keep this format, choose Yes. It won't be enough to use plain Save.
  5. Continue at step 8 and import your new and improved .csv file into Windows Live Mail instead.

If you want to be really cool, after Excel processing, open the file in a text editor and replace tabs with newlines for a prettier display of Notes in Windows Live Mail. Don't do this before Excel or try to open this new file in Excel afterward, as the newlines will confuse its CSV parser. (They are however valid, and Windows Live Mail will take the file just fine.)

On top of that, if you know how, you can search within the .eml files yourself for lines containing: Reply-to and correcting any contact name/addresses with these lines. Unfortunately the Python script doesn't yet handle these automatically.

Finally

Hooray! Contacts recovered! At least as many as in your emails. Better than nothing! I showed that machine who's boss. *flexes programming prowess* Next time no backup deleting idiocy. Also, have a backup to begin with, but you already knew that.