Can the SQLite databases that store iOS mail be exploited to back up messages? Being the technical dude of the family I'm confronted with the following problem:

An iPhone 3GS with iOS 3.1.2, the owner has a lot of old email messages stored on the device but has lost access to the original email server. Other copies of these messages were safely stored on a laptop but the hard disk died.

Forwarding each message manually from the device is not an option given the amount of work involved (about 2000 messages).

I'm fairly technical but without any experience with Macs or iPhones. Reading around a bit I learned the following:


There's no straightforward way to backup email messages (you can backup email account settings but not the actual content).
There's no way to mark all messages on the device and move them to an IMAP folder so they would sync up to a new mail server.
Messages are stored in a SQLite database file on the device. You cannot access this file and move it to your PC or mail it to yourself unless you jailbreak and unlock the device.


First of all, am I wrong and there is some magical way or utility to transfer messages from the device to a PC? Assuming there isn't, can someone point me to the right jailbreak and unlocking procedures that will not delete all data from the device and allow me to get that SQLite store safely?

I'd love to learn if it's possible to read these databases and make a backup of my Mail by accessing the backup files or the files directly on the device.

Is this possible?
I was searching for information on this myself because I needed to back up my email data from the device before doing a restore (it's just shameful that Apple doesn't consider your email messages to be important enough to include in its backups). The following information is valid for IOS 6, I hope it applies to your situation with IOS 3 as well.  On IOS 6 at least, you won't need to mess around with SQlite or anything, it's all plain text.

You need access to the filesystem on the device. There are various PC and Mac apps that will browse the files on the device -- Ifunbox is one that claims to allow access to the filesystem without jailbreaking.

Instructions for jailbreaking your specific device (if it turns out you need it) can be found at http://stateofjailbreak.com/guide/iphone-3gs/3-1-2/.

The emails are stored in User/Library/Mail (that's a symlink, the actual path seems to be var/mobile/library/mail).  Just copy the whole thing to your laptop.  

Inside there, you'll find directories named after each email account set up on the device. There's a pretty self-explanatory folder structure within each account folder.  Once you drill down, the emails themselves are stored in individual plaintext *.emlx files, complete with all headers and uuencoded attachments (there's also sometimes an "attachments" folder which has the extracted version of the attachments).  On a PC, you'll want to rename them to *.eml files, and then you'll be able to import them into various email programs like Thunderbird or Outlook; with some you'll need a utility, with others the import function is built in.

I haven't gotten far enough to determine if copying a backup of these folders onto a device restored from itunes backup will restore your archive of emails or not.  Did I mention how annoying it is that Apple doesn't think your offline emails are worth saving when you do a backup of your device?