AutoHotkey Community

It is currently May 26th, 2012, 4:23 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: May 13th, 2008, 10:50 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Hello, long time not coming back here!
I fear I won't come back often, so I might miss questions, requests and such...
Oh, I will just activate the notify option, for once.

Recently, I goofed in Thunderbird. I don't know how, but I managed to do Ctrl+A quickly followed by Shift+Delete in my main Inbox... o_O
If you don't know what it does, I advise not to try: it selects all messages, then delete them straight, without putting them to the trash can.

After few seconds of confusion, I didn't lose my self-control and went to my Thunderbird profile folder. I made a copy of the Inbox file (15MB! and I dispatch to lot of folders...).
If you don't know yet, a folder in Thunderbird is just a file in the Unix mbox (mailbox) format, which is plain text in Mime format. That's one of the main reasons why I switched from Outlook (proprietary binary format) to Thunderbird.

One nice thing in Thunderbird is that it doesn't delete messages immediately from the file, as it can be time consuming (moving up some MB of data in the file). So instead it overwrites some bytes, to mark the message as deleted.
That's why from time to time, it asks you if you want to compact your folders: it rewrites the file after removing all the messages marked as deleted.
Note it is a good idea to backup these files from time to time (I didn't do it... :().

So I had this big file full of dead messages: if I rename it, it appears as a new folder, but empty. A quick glance showed there were these X-Mozilla-Status and X-Mozilla-Status2 fields in the headers. First hit in Google is very helpful: http://www.eyrich-net.org/mozilla/X-Moz ... us.html?en

So to restore all my messages, all I had to do is to change in the file all the X-Mozilla-Status fields to set off the bit 0x0008.
Boy, I am rusty in my AHK coding! I made several bloopers before making it working (writing "line" all over the file, forgetting to set the hexa mode, etc.).
Advice: make a copy, no, several copies of the file you need to manipulate. I am not responsible if you loose all your messages!
And operate while Thunderbird is closed.

Note: you can delete the .msf file of same name as your folder. That's the Mail Summary File, ie. an index for quick access to essential data of the folder (number of messages, of unread messages, size, etc.). If absent, it is automatically re-created.

No more chatting, the code:
Code:
/*
UndeleteMessages.ahk

Read a mailbox file from Thunderbird (mbox format, with X-Mozilla-Status lines)
and undelete all messages.
See http://www.eyrich-net.org/mozilla/X-Mozilla-Status.html?en for the meaning of the bits of this status.

// by Philippe Lhoste <PhiLho(a)GMX.net> http://Phi.Lho.free.fr
// File/Project history:
 1.00.000 -- 2008/05/13 (PL) -- Creation.
*/
/* Copyright notice: See the PhiLhoSoftLicence.txt file for details.
This file is distributed under the zlib/libpng license.
Copyright (c) 2008 Philippe Lhoste / PhiLhoSoft
*/
#SingleInstance Force
#NoEnv
SetFormat Integer, Hex

; The mail folder (a file), of the name of your folder in TB
fileIn = E:\Documents\Net\Thunderbird\Profiles\ProfileCode.default\Mail\AccountName\Inbox
; A different file! Can go elsewhere, at the end you will replace the previous file with this one
fileOut = E:\Documents\Net\Thunderbird\Profiles\ProfileCode.default\Mail\AccountName\InboxUD
; ProfileCode and AccountName depends on your config.

Loop Read, %fileIn%, %fileOut%
{
   line := A_LoopReadLine
   If (RegExMatch(line, "^X-Mozilla-Status: (\d{4})$", digits) > 0)
   {
      digits := digits1 & 0xFFF7 ; Erase bit (flag) indicating the message is deleted
      digits = 0000%digits%
      StringRight digits, digits, 4 ; Format to 4 digits
      line = X-Mozilla-Status: %digits%
   }
   FileAppend %line%`r`n
}


This will undelete messages voluntarily deleted since last compacting, but that's the least of my concerns... It can also alter body of messages if you have X-Mozilla-Status: nnnn alone in a line in a message, which is rather unlikely...

That's where I see that AHK is very fast: the 15MB file is processed in a few seconds on a 4 years old computer.

If you know what you are doing, you can use this base for other processes: reset all the marked messages, change flags on messages matching a given subject or sender (a bit harder, need buffering of headers), etc.

I hope nobody will have the need to use it, but in case of emergency, it is available!

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 14th, 2008, 3:10 pm 
Offline

Joined: July 21st, 2006, 12:26 am
Posts: 223
neat, thanks for sharing this information ;) it will be sure useful one day.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks!
PostPosted: August 4th, 2008, 12:55 am 
Truly appreciate your posting. My daughter did what you described and you provided the information needed for me to be able to recover my e-mail. In my case, I took the copy of the "Inbox" that I created, opened with notepad and did a replace of all 0008 with 0001 and it worked.

Thanks again, this was most helpful!!!!

ALD 66


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group