Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | #!/import/bw/tools/local/perl-5.8.0/bin/perl |
2 | use lib qw(/import/bw/tools/local/perl-5.8.0/lib/site_perl/5.8.0); | |
3 | #!/usr/local/bin/perl | |
4 | ##---------------------------------------------------------------------------## | |
5 | ## File: | |
6 | ## $Id: mha-dbrecover,v 1.6 2001/11/18 07:25:34 ehood Exp $ | |
7 | ## Author: | |
8 | ## Earl Hood mhonarc@mhonarc.org | |
9 | ## Description: | |
10 | ## Program to rebuild the MHonArc database file from message files. | |
11 | ##---------------------------------------------------------------------------## | |
12 | ## MHonArc -- Internet mail-to-HTML converter | |
13 | ## Copyright (C) 1998,2001 Earl Hood, mhonarc@mhonarc.org | |
14 | ## | |
15 | ## This program is free software; you can redistribute it and/or modify | |
16 | ## it under the terms of the GNU General Public License as published by | |
17 | ## the Free Software Foundation; either version 2 of the License, or | |
18 | ## (at your option) any later version. | |
19 | ## | |
20 | ## This program is distributed in the hope that it will be useful, | |
21 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | ## GNU General Public License for more details. | |
24 | ## | |
25 | ## You should have received a copy of the GNU General Public License | |
26 | ## along with this program; if not, write to the Free Software | |
27 | ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
28 | ## 02111-1307, USA | |
29 | ##---------------------------------------------------------------------------## | |
30 | ||
31 | package mha_dbrecover; | |
32 | ||
33 | use Getopt::Long; | |
34 | ||
35 | ##---------------------------------------------------------------------------## | |
36 | ## Main routine ## | |
37 | ##---------------------------------------------------------------------------## | |
38 | ||
39 | MAIN: { | |
40 | unshift(@INC, 'lib'); # Should I leave this line in? | |
41 | ||
42 | ## Grab options from @ARGV unique to this program | |
43 | my %opts = ( ); | |
44 | Getopt::Long::Configure('pass_through'); | |
45 | GetOptions(\%opts, | |
46 | 'dbr-startnum=i', | |
47 | 'dbr-endnum=i' | |
48 | ); | |
49 | my $startnum = $opts{'dbr-startnum'} || 0; | |
50 | my $endnum = $opts{'dbr-endnum'} || -1; | |
51 | ||
52 | ## Reset pass-through of options | |
53 | Getopt::Long::Configure('no_pass_through'); | |
54 | ||
55 | ## Initialize MHonArc | |
56 | require 'mhamain.pl' || die qq/ERROR: Unable to require "mhamain.pl"\n/; | |
57 | mhonarc::initialize(); | |
58 | ||
59 | ## Load library for reading message files | |
60 | require 'mhmsgfile.pl' || | |
61 | die qq/ERROR: Unable to require "mhmsgfile.pl"\n/; | |
62 | ||
63 | ## Open archive: We use special -noarg option to tell mhonarc | |
64 | ## to not do any processing, just open archive and lock it. | |
65 | unshift(@ARGV, '-noarg', '-lock'); | |
66 | if (!mhonarc::open_archive()) { | |
67 | # unable to open, so abort processing | |
68 | die "ERROR: Unable to open archive\n"; | |
69 | } | |
70 | ||
71 | ## do it | |
72 | eval { | |
73 | local(*DIR); | |
74 | if (!opendir(DIR, $mhonarc::OUTDIR)) { | |
75 | # unable to open archive directory | |
76 | die qq/ERROR: Unable to open "$mhonarc::OUTDIR": $!\n"/; | |
77 | } | |
78 | ||
79 | print STDOUT "Rebuilding database in $mhonarc::OUTDIR ...\n" | |
80 | unless $mhonarc::QUIET; | |
81 | ||
82 | ## Define regular expressing for matching message files: | |
83 | ## we use message prefix and extension settings as defined | |
84 | ## by mhonarc. Make sure to capture message number from | |
85 | ## filename. | |
86 | my $msgrex = '^'. | |
87 | "\Q$mhonarc::MsgPrefix". | |
88 | '(\d+)\.'. | |
89 | "\Q$mhonarc::HtmlExt". | |
90 | '$'; | |
91 | local($_); | |
92 | my(@file); | |
93 | foreach (readdir(DIR)) { | |
94 | # skip if not a message file | |
95 | next unless /$msgrex/o; | |
96 | # skip if number less than start | |
97 | next if $1 < $startnum; | |
98 | # skip if number greater than end | |
99 | next if ($endnum >= 0) && ($1 > $endnum); | |
100 | ||
101 | # add file to list to process | |
102 | push @file, $_; | |
103 | } | |
104 | closedir(DIR); | |
105 | if (!@file) { | |
106 | # nothing found to process | |
107 | die qq/ERROR: No message files found\n/; | |
108 | } | |
109 | ||
110 | ## Read files. Use function in mhmsgfile.pl to extract data. | |
111 | my($file, $num); | |
112 | foreach (@file) { | |
113 | # get number for loading into mhonarc data structures | |
114 | ($num) = $_ =~ /$msgrex/o; | |
115 | print STDOUT "." unless $mhonarc::QUIET; | |
116 | $file = join($mhonarc::DIRSEP, $mhonarc::OUTDIR, $_); | |
117 | # load date from message file into mhonarc | |
118 | mhonarc::load_data_from_msg_file($file, $num); | |
119 | } | |
120 | ||
121 | ## Define other data structures that need to be recovered. | |
122 | $mhonarc::NumOfMsgs = scalar(@file); | |
123 | @mhonarc::MListOrder = mhonarc::sort_messages(); | |
124 | mhonarc::compute_follow_ups(\@mhonarc::MListOrder); | |
125 | mhonarc::compute_threads(); | |
126 | ||
127 | ## Output recovered database file | |
128 | print STDOUT "\nWriting database ...\n" | |
129 | unless $mhonarc::QUIET; | |
130 | mhonarc::output_db($mhonarc::DBPathName); | |
131 | }; | |
132 | my $ec = 0; | |
133 | if ($@) { warn $@; $ec = 1; } | |
134 | ||
135 | mhonarc::close_archive(); | |
136 | exit($ec); | |
137 | } | |
138 | ||
139 | ##---------------------------------------------------------------------------## | |
140 | 1; | |
141 | ||
142 | __END__ | |
143 | ||
144 | =head1 NAME | |
145 | ||
146 | mha-dbrecover - rebuild a MHonArc archive database | |
147 | ||
148 | =head1 SYNOPSIS | |
149 | ||
150 | S<B<mha-dbrecover> [I<options>]> | |
151 | ||
152 | =head1 DESCRIPTION | |
153 | ||
154 | B<mha-dbrecover> is a utility program that is part of the B<MHonArc> | |
155 | software package. The program allows can be used to rebuild a | |
156 | B<MHonArc> archive database from the HTML message files. This allows | |
157 | database recovery if the database gets corrupted or accidentally | |
158 | deleted. | |
159 | ||
160 | The documentation for B<MHonArc> is distributed in HTML format. | |
161 | Due to its size and organization, it is not suited for manpage | |
162 | format. Consult your system administrator for where the documentation | |
163 | has been installed, or see L<"AVAILABILITY"> on where you can | |
164 | access the documentation on the web. | |
165 | ||
166 | =head1 OPTIONS | |
167 | ||
168 | B<mha-dbrecover> takes all the options available to B<mhonarc> along | |
169 | with the following additional options: | |
170 | ||
171 | =over | |
172 | ||
173 | =item C<-dbr-startnum> I<#> | |
174 | ||
175 | The starting message number to recover data from. This option is | |
176 | useful if you have many message files in a directory, but you only | |
177 | want to recover a subset of the files. | |
178 | ||
179 | If this option is not specified, the starting number is 0. | |
180 | ||
181 | =item C<-dbr-endnum> I<#> | |
182 | ||
183 | The ending message number to recover data from. This option is | |
184 | useful if you have many message files in a directory, but you only | |
185 | want to recover a subset of the files. | |
186 | ||
187 | If this option is not specified, all messages starting from | |
188 | C<-dbr-startnum> will be recovered. | |
189 | ||
190 | =back | |
191 | ||
192 | B<NOTE:> Only a subset of the options available to B<mhonarc> | |
193 | are actually supported since many options are not applicable for | |
194 | recovering operations. | |
195 | ||
196 | =head1 AVAILABILITY | |
197 | ||
198 | E<lt>I<http://www.mhonarc.org/>E<gt> | |
199 | ||
200 | =head1 AUTHOR | |
201 | ||
202 | Earl Hood, mhonarc@mhonarc.org | |
203 | ||
204 | =cut | |
205 |