So tonight I was switching around some windows, and accidently managed to delete (shift-delete nonetheless) all the emails from my inbox in one of my accounts. This is a lot of email, and while I had some older backups, I hoped that maybe I could restore them (even from a shift-delete).
The first thing that I hoped I had going for me is that generally when you delete an email, it really just flags it, not removes it. When you do a compact folder, it goes through and cleans up those deleted emails. So I immediately closed the application and dropped to a command prompt. This looked promising:
foyc@dilbert ~/.thunderbird/[account] $ ls -l Inbox
-rw-rw-rw- 1 foyc users 843590900 Jan 1 17:56 Inbox
Ok, it’s large enough to hopefully still have the emails in it. So I copy it out to a working folder. Now let’s see what is inside of it. I do a
tail -n 1000 Inbox and see these interesting headers:
So off to the web I go. Christian Eyrich has a great page explaining the status codes. The relevant bit is that 0x0008 is “Already Gone”. Changing that to 0x0001 “Message has been read” should bring them back. Since it has been a long time since I’ve compacted, I’m probably going to undelete a bunch of email that I thought was gone, but that’s worth it here.
So, let’s make the change. Just to check myself, let’s see if the messages look to be deleted:
tail -n 50000 Inbox | grep 'X-Mozilla-Status'
sed should be able to help us out nicely here, so let’s try that out:
foyc@dilbert ~ $ sed 's/X-Mozilla-Status: 0008/X-Mozilla-Status: 0001/g' Inbox > FixedInbox
And let’s sanity check the change:
foyc@dilbert ~ $ ls -l FixedInbox
-rw-r--r-- 1 foyc users 843590900 Jan 1 18:41 FixedInbox
foyc@dilbert ~ $ ls -l Inbox
-rw-r--r-- 1 foyc users 843590900 Jan 1 18:17 Inbox
tail -n 50000 FixedInbox | grep 'X-Mozilla-Status'
Ok, so let’s see if this fixes it. I’m going to move the existing Inbox, copy the FixedInbox to the same location (renaming it Inbox) and fire up Thunderbird.
foyc@dilbert ~/.thunderbird/[account] $
mv Inbox Inbox-deleted
foyc@dilbert ~/.thunderbird/[account] $ mv ~/FixedInbox Inbox
and…viola! All of my emails (including *lots* I thought were gone) are back!
It’s times like this I am glad for open standards and the ability to look at things like the data file. If Thunderbird had stored the emails as binary, or some proprietary format, I probably would have either had to go buy special software, or just chalked it up to not being careful and backing up that file more often. But thanks to their willingness to be open, I was able to fix a stupid mistake myself.