mbx repair script

Donn Cave donn at u.washington.edu
Thu Apr 28 12:14:55 EDT 2005


In article <gMUbe.2502$iZ1.2213 at trnddc03>,
 "David Isaac" <aisaac0 at verizon.net> wrote:

> I'm looking for a Python script to repair the mbx header
> for a mail file where only the header is corrupted.

"Repair" and "corrupted" covers a lot of territory.

In the simplest case, a Python script would just be
a nuisance.  All mbx files start with a 2048 byte
header, and a valid header can be copied to another
file and still be valid.  For example, if the damaged
file still has 2048 bytes of header,

   1.  Find or create another mbx file "spud".
   2.  Copy header:    $ dd if=spud count=4 > newbx
   3.  Copy old file:  $ dd if=oldbx skip=4 >> newbx
   4.  change ownership and permission to match oldbx.

This approach isn't perfect - for example, it doesn't
preserve user flag information, but then, user flags
can be messed up by common IMAP4 operations like copying
a message from one folder to another.  It assumes you
know where message data actually starts in the file,
but I think you'd need to know that in any event.

If the damage is really just that someone edited the
file in vi and you need to restore the NUL characters,
you could probably write something.  Again, you have
to be able to recognize the start of message data
(or rather, the first MBX message header line.)  If
the NULs are gone, this is probably preceded by a
series of CRLF ('\r\n'.)  Keep track of how much has
been written to the output file, and at this point,
write '\0'*(2048 - n).

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list