MAJOR=4
MINOR=43
DEVNAME=tty43
  6   ˆl–Ü4ý(&Ô¾R( *ËŒ¿q°©‹Fÿ�þBû®,ÜŒÊ(ä­Æ@?¿ƒq°½ÄÂÁ v    #!/usr/bin/perl
use lib qw(/usr/share/mhonarc);
#!/usr/bin/perl
##---------------------------------------------------------------------------##
##  File:
##	$Id: mha-dbrecover,v 1.9 2009/05/03 20:11:27 ehood Exp $
##  Author:
##      Earl Hood       mhonarc@mhonarc.org
##  Description:
##      Program to rebuild the MHonArc database file from message files.
##---------------------------------------------------------------------------##
##    MHonArc -- Internet mail-to-HTML converter
##    Copyright (C) 1998,2001	Earl Hood, mhonarc@mhonarc.org
##
##    This program is free software; you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation; either version 2 of the License, or
##    (at your option) any later version.
##
##    This program is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with this program; if not, write to the Free Software
##    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
##    02111-1307, USA
##---------------------------------------------------------------------------##

package mha_dbrecover;

use Getopt::Long;

##---------------------------------------------------------------------------##
##				Main routine				     ##
##---------------------------------------------------------------------------##

MAIN: {
    unshift(@INC, 'lib');	# Should I leave this line in?

    ## Grab options from @ARGV unique to this program
    my %opts = ( );
    Getopt::Long::Configure('pass_through');
    GetOptions(\%opts,
      'dbr-startnum=i',
      'dbr-endnum=i'
    );
    my $startnum = $opts{'dbr-startnum'} || 0;
    my $endnum   = $opts{'dbr-endnum'}   || -1;

    ## Reset pass-through of options
    Getopt::Long::Configure('no_pass_through');

    ## Initialize MHonArc
    require 'mhamain.pl' || die qq/ERROR: Unable to require "mhamain.pl"\n/;
    mhonarc::initialize();

    ## Load library for reading message files
    require 'mhmsgfile.pl' ||
    	die qq/ERROR: Unable to require "mhmsgfile.pl"\n/;

    ## Open archive: We use special -noarg option to tell mhonarc
    ## to not do any processing, just open archive and lock it.
    unshift(@ARGV, '-noarg', '-lock');
    if (!mhonarc::open_archive()) {
	# unable to open, so abort processing
	die "ERROR: Unable to open archive\n";
    }

    ## do it
    eval {
	local(*DIR);
	if (!opendir(DIR, $mhonarc::OUTDIR)) {
	    # unable to open archive directory
	    die qq/ERROR: Unable to open "$mhonarc::OUTDIR": $!\n"/;
	}

	print STDOUT "Rebuilding database in $mhonarc::OUTDIR ...\n"
	    unless $mhonarc::QUIET;

	## Define regular expressing for matching message files:
	## we use message prefix and extension settings as defined
	## by mhonarc.  Make sure to capture message number from
	## filename.
	my $msgrex = '^'.
		     "\Q$mhonarc::MsgPrefix".
		     '(\d+)\.'.
		     "\Q$mhonarc::HtmlExt".
		     '$';
	local($_);
	my(@file);
	foreach (readdir(DIR)) {
	    # skip if not a message file
	    next  unless /$msgrex/o;
	    # skip if number less than start
	    next  if $1 < $startnum;
	    # skip if number greater than end
	    next  if ($endnum >= 0) && ($1 > $endnum);

	    # add file to list to process
	    push @file, $_;
	}
	closedir(DIR);
	if (!@file) {
	    # nothing found to process
	    die qq/ERROR: No message files found\n/;
	}

	## Read files.  Use function in mhmsgfile.pl to extract data.
	my($file, $num);
	foreach (@file) {
	    # get number for loading into mhonarc data structures
	    ($num) = $_ =~ /$msgrex/o;
	    print STDOUT "."  unless $mhonarc::QUIET;
	    $file = join($mhonarc::DIRSEP, $mhonarc::OUTDIR, $_);
	    # load date from message file into mhonarc
	    mhonarc