James G. Sack (jim) wrote:
DJA wrote:
DJA wrote:
I think I accidentally deleted all the email in one Thunderbird
account's Inbox folder. And of course, because I didn't know I'd done
it, I also emptied the Trash folder. I'd like to get that mail back.

I have backed up both the Inbox, Inbox.msf, Trash, and Trash.msf
folders. Given their size, I can see that they probably still contain
the recently deleted email. I can also read the contents of both the
Inbox and Trash folders.

I've done the "Change the X-Mozilla-Status: value to 0000 thing" but
that does not seem to have any effect. I suspect that there is some
combination of mechanisms in MTB (Thunderbird) whereby not only is
mail in the original folder (Inbox) marked as deleted, but it's also
marked as deleted in the Trash folder. Maybe even somewhere else as well.

[snip)

Instead, I created a dummy email account (Inbox_maintenance), with a
dummy user (dummy@<IN_address>. This created an empty directory
structure for that account. Next I shut down Thunderbird.

I then copied the problem Inbox, Inbox.msf, Trash, and Trash.msf files
to the Inbox_maintenance account (overwriting the existing files).

Edit the transplanted files, changing the X-Mozilla-Status: nnnn values
to reset the 8 bit, and only the 8 bit on the LSB of the nnnn part of
the string. That is, if nnnn = 001b, then change it to 0013; change 0008
to 0000, etc.

Restart Thunderbird.

This caused the deleted email to become undeleted again. This works for
both the Inbox and Trash mbox files. I suppose that one need not
transplant the .msf files as MTB will just rebuild those on start anyway.

Part Two

There's no way I want to manually and individually do the above
procedure for the 5-10 thousand emails in just the Inbox file alone, let
alone that plus the 3+ MB in the Trash folder. So I need to automate the
above procedure. I'm neither a scripting nor a Perl (or whatever)
expert, so I'd appreciate any recipes for scripting/programming the
change to the X-Mozilla-Status variable as shown above.

Here is a list I found showing the possible values of X-Mozilla-Status:

my $MSG_FLAG_READ          = 0x0001;
my $MSG_FLAG_REPLIED       = 0x0002;
my $MSG_FLAG_MARKED        = 0x0004;
my $MSG_FLAG_EXPUNGED      = 0x0008;
my $MSG_FLAG_HAS_RE        = 0x0010;
my $MSG_FLAG_ELIDED        = 0x0020;
my $MSG_FLAG_OFFLINE       = 0x0080;
my $MSG_FLAG_WATCHED       = 0x0100;
my $MSG_FLAG_SENDER_AUTHED = 0x0200;
my $MSG_FLAG_PARTIAL       = 0x0400;
my $MSG_FLAG_QUEUED        = 0x0800;
my $MSG_FLAG_FORWARDED     = 0x1000;
my $MSG_FLAG_PRIORITIES    = 0xE000;



Well, here's a one-liner to try:
-----------------------------------------------------------------------
perl -lpe '$_=sprintf("X-Mozilla-Status: %.4x", 0xFFF7 & hex("$1")) if
/^X-Mozilla-Status: ([0-9a-f]{4})$/' Inbox >I2
-----------------------------------------------------------------------

Explanation:
  perl -lpe '...' Inbox > I2 reads and prints lines from Inbox to I2
  lines matching the pattern /.../ are _modified_ by
    replacing the trailing hex with the value anded with 0xFFF7
    (4 chars are interpreted as hex, anded, then printed as hex)
    (0xFFF7 being ~ 0x0008, of course)
  other lines are printed unchanged
  newlines are stripped on read, added on write

Hope I understood the challenge, correctly.

Regards,
..jim

Thanks, that seems to have worked. I say "seemed" because I don't know how many emails I actually had in that account: I rarely get email in that account that doesn't get filtered to other folders, plus the recovery process brought back not only the good, but also the bad (e.g. spam, and stuff that should stay dead).

A couple of other notes.:

Make sure if this happens to you, that you _don't_ compact the damaged folder. Doing so will *guarantee* your mail is gone. Compacting culls the email marked as deleted from the mbox file, and rebuilds the index (.msf) file.

The presence of the .msf file has no affect on its associated mbox file as regards data recovery, as far as I can tell.

Running the undelete script (or undeleting manually) will not restore the affected folder's contents. I could only get the recovered email back to the original folder(s) by copying it from the dummy account folder(s).

The steps I took in trying the undelete script on the mbox (Inbox and Trash) files in the original account were

1) Quit MTB,
2) save the original Inbox, Inbox.mfs and Trash files,
3) remove the .msf files from the original account tree,
4) run the undelete script,
5) copy the scripts output files over the originals, and
6) run MTB again.

After that, the files still did not show up in either the Inbox or Trash folders of the original account. So I just copied them from the dummy account. Had I not deleted the original .mfs file(s) maybe the outcome would have been different. I don't think so.

To do ...

7) Add another 250 GB drive to my Infrant X6,
8) set up partitions to backup /home dirs of workstations, and
7) set scheduling on X6 to do an Rsync pull of those boxes.

--
   Best Regards,
      ~DJA.


--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to