Undelete a message

From MozillaZine Knowledge Base
Jump to navigationJump to search
This article was written for Thunderbird but also applies to Mozilla Suite / SeaMonkey (though some menu sequences may differ).

Deleted messages aren't physically deleted from your disk until the folder is compacted in Thunderbird. Deleted messages are hidden from view and the X-Mozilla-Status: message header modified to indicate the message has been deleted. The deleted message is also typically copied to the Trash folder. So if you accidentally delete a message you can recover it from the Trash folder if it hasn't been emptied. If you haven't exited Thunderbird you can try using "Ctrl+Z" to undo a action (repeat as needed). Otherwise Thunderbird (normally) doesn't provide a way to undelete the message. However, its still possible to undelete a message as long as you haven't compacted the folder.

The only difference between Shift+Delete and Delete is that it doesn't copy the message to the Trash folder before marking the message as deleted. So all of the methods in this article should work with it too.

Recover deleted messages add-on

The Recover deleted messages add-on adds "Recover deleted messages" to the folders context menu (right click on the folder). It will work with any folder that has a mbox file (POP account, Local Folders, or IMAP offline folders created via Tools -> Account Settings -> Synchronizing & Storage) if you haven't compacted the folder yet.

POP account (mbox files)

Thunderbird adds a Edit -> Undo Delete Message menu command if you delete a message or a folder in a POP account or the local folders directory. It lets you undelete the message or a folder if you haven't exited Thunderbird or compacted the folder yet. If you can't use that there are four different approaches. Which one is most appropriate depends upon how many messages you need to recover and how technical you are.

All of the messages for a folder are stored in a text file called an mbox file that has the folder's name and no file extension. The mbox file is stored in the account's local directory. To find this, look in the Account settings, on the account's Server Settings page. Alternatively, get a context menu for the folder (for example, by right-clicking it), choose Copy Folder Location, and paste the location somewhere you can read it.

If you are using Windows Explorer you may need to configure Tools -> Folder Options -> View to show hidden/system files.

For example, if you want to undelete a message in your gmail account's Inbox under XP, and your Windows user account name is JohnSmith, and your gmail account is stored in your profile:

  1. Go to the profile directory. It will typically be at C:\Documents and Settings\JohnSmith\Application Data\Thunderbird\Profiles\xxxxxxx.default user where xxxxxxx is some random sequence of letters and numbers.
  2. Goto the Mail subdirectory.
  3. Goto the pop.gmail.com subdirectory. All of the messages for an account are stored in a subdirectory named after the mail server. If you were using a global Inbox you would go to the Local Folders directory instead.
  4. Find the file named Inbox with no extension.
  5. Choose one methods below. Editing the X-Mozilla-Status: header is the best solution if you're comfortable editing the mbox file, since it truly undeletes the message.

Copy and paste the text from the mbox file

Save a copy of the mbox file and then open it with a text editor. The messages are stored "as is" one after another, each seperated by a blank line and a From_ line. A From_ line starts with "From " and has the time and date. For example: From - Wed Oct 27 11:08:59 2004 . If you see any big blocks of characters all run together thats probably the base64 encoded data for an attachment. Thats how it embeds 8-bit data such as a .JPEG file in a 7-bit message.

Browse the text file until you see the message you want to recover. Copy and paste the message body to a new message in Thunderbird.

Edit the X-Mozilla-Status: header in the mbox file

Save a copy of the mbox file and then open it with a text editor. The messages are stored "as is" one after another, each seperated by a blank line and a From_ line. A From_ line starts with "From " and has the time and date. For example: From - Wed Oct 27 11:08:59 2004 . If you see any big blocks of characters all run together thats probably the base64 encoded data for an attachment. Thats how it embeds 8-bit data such as a .JPEG file in a 7-bit message.

Browse the text file until you see the message you want to recover. Find the X-Mozilla-Status: header. It should look something like X-Mozilla-Status: 1001 . The number will vary. Edit that value to zero and save the file. The next time you run Thunderbird it should think the message is a new unread message.

If this doesn't work look for a line beginning with >From in the message body. Remove the '>'. Thunderbird uses "From quoting" to help it distinguish between the From_ line used to seperate messages and some line in the message body that starts with From. Sometimes that causes problems.

Use Thunderbird Reset Status program plus ImportExportTools

1. Save a copy of the mbox file in a empty directory.

2. Download Thunderbird Reset Status (Windows, Linux) and run it on the mbox file to reset the messages status.

3. Import the .mbx file using the ImportExportTools extension. This should create a a copy of the folder with all of the messages undeleted.

Note: The author of Thunderbird Reset Status warns that the program still needs more testing. Permission to port it to other platforms is in the readme.txt file.

Convert the mbox file to .EML files

You can use a utility program to convert the messages in the folder into .EML files. This will not effect the mbox file (your Thunderbird folder). The utility program doesn't understand the X-Mozilla-Status header so it doesn't know the message is deleted.

If you're using Windows download and install IMAPSize. Don't be mislead by the name, you don't need a IMAP account to use it. Select Tools -> mbox2eml. Select the mbox file in "choose one mbox file to convert" and where you want to store the .EML files in "chose folder where eml files for this mbox will be saved". You may need to need to choose "All files" in "Files of type:" since Thunderbirds mbox files don't end in .mbox. Then press the Convert button.

Otherwise you could use the Java based mbox2eml program.

Your .EML file still contains a header saying its been deleted so you don't want to import it as a message in Thunderbird. You could drag and drop the message into a folder window within Outlook Express (while its running). That will import it as a message in that folder. Then you could forward the message to yourself. That adds a new set of headers so Thunderbird will ignore the old X-Mozilla-Status header (which says its deleted). You could also copy and paste the message body into a new message in Thunderbird or send it as an attachment.

POP account (message still on server)

In your POP account settings you can tell Thunderbird to leave messages on the server. If you delete a message from Thunderbird and it is still on the server, you can download the message again by removing the message's entry from the account's popstate.dat file.

Folders (mbox files)

Deleted folders aren't stored in the Trash folder since mbox files don't have any concept of a folder or a folder hierarchy. They just have messages, and the folder name is derived from the filename. Deleted folders are moved to the Trash.sbd subdirectory. That subdirectory doesn't exist by default, its created when needed and will be deleted when you empty the trash. Deleted messages aren't physically deleted until the folder is compacted. That is not true with deleted folders, they're physically deleted when you empty the trash.

Normally you can undelete a folder by dragging and dropping it from the Trash folder to another folder. If that doesn't work or its not practical for some reason try moving the mbox and index file for the deleted folder out of the Trash.sbd directory tree.

If you delete a folder called test Thunderbird will move "test." (the mbox file with the messages) and "test.msf" (the index file) to the Trash.sbd subdirectory for that account. You can undelete the folder by moving the two files back to their original location. If you can't figure out where the two files where originally stored, just copy them to ..\Mail\Local Folders and move the messages to wherever you want them later on using Thunderbird. Or import the mbox file ("test.") using the ImportExportTools extension.

You may need to restart Thunderbird or collapse and expand the folder tree in the folder pane to force Thunderbird to refresh the list of folders.

IMAP account

IMAP accounts support remote folders that you can access as if they're local folders, and normally only download the headers to the hard disk. Tools -> Account Settings -> Server Settings -> "when I delete a message" has a list box with three settings. If you had used "Mark it as deleted" the message is still visible and you can undelete it by just deleting it again. If you had used "Move it to the Trash folder" (the default value) or "Remove it immediately" you need to use a browser and login into webmail. Most webmail accounts will display messages marked for deletion by other email clients. They may draw a line through the listing in the folder or display a flag to indicate its deleted. The safest way to undelete it is to forward the message to yourself since that creates a new message.

See also

External links