MHonArc database reconstruction script

1997-04-21 09:59:11
The following contribution comes from Stephane Bortzmeyer.  I
have not personally tested the script, so I cannot vouch for
its fitness.  However, Stephane appears to have had success
with it, and I am sure others who have lossed there mhonarc
database can benefit from it.

--- Begin Message ---

In the excellent MHonarc FAQ 
you say:

Can I reconstruct a database from the HTML messages? 

Maybe. There is currently no utility to perform this task, but is possible to 
write one. The utility can scan
each HTML messages and extract the necessary information required to restore 
the database. How well
the database is reconstructed is heavily dependent on how the messages are 
formatted. v2.0 messages
contain more comment declarations at the top of each message to provide better 
recovering support over
earlier versions.

Having rmed my database :-( I had to write such a program. I include it at the 
it seems quite simple, while necessiting a few text edition after (you just 
have to
include the output of my program in an empty database).


require '';
require '/web/mail/MHonArc/lib/';
require '/web/mail/MHonArc/lib/';

$dir = shift (@ARGV);

opendir (DIR, "$dir") || die "Cannot open $dir: $!";
while ($file = readdir (DIR)) {
    if ($file =~ /^msg([0-9]+)\.html$/) {
        $no = $1;
        open (FILE, "< $dir/$file") || die "Cannot open $file: $!";
        while (<FILE>) {
            if (/^<!--X-([^:]*): (.*)-->$/) {
                $headers{$1} = $2;
                $headers{$1} =~ s/ *$//;
        close (FILE);
        @date = &parse_date ($headers{'Date'});
        $date = &get_time_from_date ($date[1], $date[2], $date[3], $date[4], 
$date[5], $date[6]);
        $id = "$date $no";
        print STDERR "Message $id:\n";
        foreach $header (keys (%headers)) {
            print STDERR "$header: $headers{$header}\n";
            $name = $header;
            $name =~ s/-//;
            $$name{$id} = $headers{$header};
closedir (DIR);
print "%ContentType = (\n";
foreach $key (keys (%ContentType)) {
    print "\'$key\', \'$ContentType{$key}\',\n";
print ");\n";
print "%Date = (\n";
foreach $key (keys (%Date)) {
    print "\'$key\', \'$Date{$key}\',\n";
print ");\n";
print "%From = (\n";
foreach $key (keys (%From)) {
    print "\'$key\', \'$From{$key}\',\n";
print ");\n";
print "%MsgId = (\n";
foreach $key (keys (%MessageId)) {
    print "\'$key\', \'$MessageId{$key}\',\n";
print ");\n";
print "%Subject = (\n";
foreach $key (keys (%Subject)) {
    print "\'$key\', \'$Subject{$key}\',\n";
print ");\n";
print "%IndexNum = (\n";
foreach $key (keys (%MessageId)) {
    ($garbage, $num) = split (' ', $key);
    print "\'$key\', \'$num\',\n";
print ");\n";

--- End Message ---
<Prev in Thread] Current Thread [Next in Thread>
  • MHonArc database reconstruction script, Earl Hood <=