Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / mhopt.pl
CommitLineData
86530b38
AT
1##---------------------------------------------------------------------------##
2## File:
3## $Id: mhopt.pl,v 2.32 2002/10/20 03:49:22 ehood Exp $
4## Author:
5## Earl Hood mhonarc@mhonarc.org
6## Description:
7## Routines to set options for MHonArc.
8##---------------------------------------------------------------------------##
9## MHonArc -- Internet mail-to-HTML converter
10## Copyright (C) 1997-1999 Earl Hood, mhonarc@mhonarc.org
11##
12## This program is free software; you can redistribute it and/or modify
13## it under the terms of the GNU General Public License as published by
14## the Free Software Foundation; either version 2 of the License, or
15## (at your option) any later version.
16##
17## This program is distributed in the hope that it will be useful,
18## but WITHOUT ANY WARRANTY; without even the implied warranty of
19## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20## GNU General Public License for more details.
21##
22## You should have received a copy of the GNU General Public License
23## along with this program; if not, write to the Free Software
24## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25## 02111-1307, USA
26##---------------------------------------------------------------------------##
27
28package mhonarc;
29
30use Getopt::Long;
31use Time::Local;
32
33##---------------------------------------------------------------------------
34## get_resources() is responsible for grabbing resource settings from
35## the command-line and resource file(s).
36##
37sub get_resources {
38 my($tmp);
39 my(%opt) = ();
40 local($_);
41
42 die(qq{Try "$PROG -help" for usage information\n}) unless
43 GetOptions(\%opt,
44 "add", # Add a message to archive
45 "afs", # Bypass file permission checks
46 "addressmodifycode=s",
47 # Perl expression for modifying displayed addresses
48 "annotate", # Add a note to message(s)
49 "authsort", # Sort by author
50 "archive", # Create an archive (the default)
51 "conlen", # Honor Content-Length fields
52 "checknoarchive",
53 # Check for "no archive" flag in messages
54 "datefields=s", # Fields that contains the date of a message
55 "dbfile=s", # Database/state filename for mhonarc archive
56 "decodeheads", # Decode all 1522 encoded data in message headers
57 "definevar|definevars=s@",
58 # Define custom resource variables
59 "doc", # Print link to doc at end of index page
60 "docurl=s", # URL to mhonarc documentation
61 "editidx", # Change index page layout only
62 "expiredate=s", # Message cut-off date
63 "expireage=i", # Time in seconds from current if message expires
64 "folrefs", # Print links to explicit follow-ups/references
65 "footer=s", # File containing user text for bottom of index page
66 # (option no longer applicable)
67 "force", # Perform archive operation even if unable to lock
68 "fromfields=s", # Fields that contains the "from" of a message
69 "genidx", # Generate an index based upon archive contents
70 "gmtdatefmt=s", # Date specification for GMT date
71 "gzipexe=s", # Pathname of Gzip executable
72 "gzipfiles", # Gzip files
73 "gziplinks", # Add ".gz" extensions to files
74 "header=s", # File containing user text for top of index page
75 # (option no longer applicable)
76 "htmlext=s", # Extension for HTML files
77 "idxfname=s", # Filename of index page
78 "idxprefix=s", # Filename prefix for multi-page main index
79 "idxsize=i", # Maximum number of messages shown in indexes
80 "keeponrmm", # Do not delete message files on archive remove
81 "localdatefmt=s",
82 # Date specification for local date
83 "lock", # Do archive locking (default)
84 "lockdelay=i", # Time delay in seconds between lock tries
85 "lockmethod=s", # Set the method of locking
86 "locktries=i", # Number of tries in locking an archive
87 "mailtourl=s", # URL to use for e-mail address hyperlinks
88 "main", # Create a main index
89 "maxsize=i", # Maximum number of messages allowed in archive
90 "mbox", # Use mailbox format (ignored now)
91 "mh", # Use MH mail folders format (ignored now)
92 "mhpattern=s", # Regular expression for message files in a directory
93 "modtime", # Set modification time on files to message date
94 "months=s", # Month names
95 "monthsabr=s", # Abbreviated month names
96 "msgexcfilter=s",
97 # Perl expression(s) for selective message exclusion
98 "msgpgs", # Create message pages
99 "msgsep=s", # Message separator for mailbox files
100 "msgprefix=s", # Filename prefix for message files
101 "multipg", # Generate multi-page indexes
102 "news", # Add links to newsgroups
103 "noauthsort", # Do not sort by author
104 "noarchive", # Do not create an archive
105 "nochecknoarchive",
106 # Do not check for "no archive" flag in messages
107 "noconlen", # Ignore Content-Length fields
108 "nodecodeheads",
109 # Do not decode 1522 encoded data in message headers
110 "nodoc", # Do not print link to doc at end of index page
111 "nofolrefs", # Do not print links to explicit follow-ups/references
112 "nogzipfiles", # Do not Gzip files
113 "nogziplinks", # Do not add ".gz" extensions to files
114 "nokeeponrmm", # Delete message files on archive remove
115 "nolock", # Do no archive locking
116 "nomailto", # Do not add in mailto links for e-mail addresses
117 "nomain", # Do not create a main index
118 "nomsgpgs", # Do not create message pages
119 "nomodtime", # Do no set modification time on files to message date
120 "nomultipg", # Do not generate multi-page indexes
121 "nonews", # Do not add links to newsgroups
122 "noposixstrftime",
123 # Use own implementation for time format process
124 "noreverse", # List messages in normal order
125 "nosaveresources",
126 # Do not save resource values in db
127 "nosort", # Do not sort
128 "nospammode", # Do not run in (anti)spam mode
129 "nosubsort", # Do not sort by subject
130 "nosubjectthreads",
131 # Do not do subject based threading
132 "nosubjecttxt=s",
133 # Text to use if message has no subject
134 "notedir", # Location of notes
135 "notetext=s@", # Text data of note
136 "nothread", # Do not create threaded index
137 "notreverse", # List oldest thread first
138 "notsubsort|tnosubsort",
139 # Do not list threads by subject
140 "notsort|tnosort",
141 # List threads by ordered processed
142 "nourl", # Do not make URL hyperlinks
143 "otherindex|otherindexes=s@",
144 # List of other rcfiles for extra indexes
145 "outdir=s", # Destination of HTML files
146 "pagenum=s", # Page to output if -genidx
147 "perlinc=s@", # List of paths to search for MIME filters
148 "posixstrftime",
149 # Use POSIX strftime()
150 "quiet", # No status messages while running
151 "rcfile=s@", # Resource file for mhonarc
152 "varregex=s", # Regex matching resource variables
153 "reverse", # List messages in reverse order
154 "rmm", # Remove messages from an archive
155 "savemem", # Write message data while processing
156 "saveresources",
157 # Save resource values in db
158 "scan", # List out archive contents to terminal
159 "single", # Convert a single message to HTML
160 "sort", # Sort messages in increasing date order
161 "spammode", # Run in (anti)spam mode
162 "stderr=s", # Set file for stderr
163 "stdin=s", # Set file for stdin
164 "stdout=s", # Set file for stdout
165 "subjectarticlerxp=s",
166 # Regex for leading articles in subjects
167 "subjectreplyrxp=s",
168 # Regex for leading reply string in subjects
169 "subjectstripcode=s",
170 # Perl expression for modifying subjects
171 "subjectthreads",
172 # Check subjects for threads
173 "subsort", # Sort message by subject
174 "tidxfname=s", # File name of threaded index page
175 "tidxprefix=s", # Filename prefix for multi-page thread index
176 "time", # Print processing time
177 "title=s", # Title of index page
178 "ttitle=s", # Title of threaded index page
179 "thread", # Create threaded index
180 "tlevels=i", # Maximum # of nested lists in threaded index
181 "treverse", # Reverse order of thread listing
182 "tslice=s", # Set size of thread slice listing
183 "tslicelevels=i",
184 # Maximum # of nested lists in thread slices
185 "tsort", # List threads by date
186 "tsubsort", # List threads by subject
187 "umask=i", # Set umask of process
188 "url", # Make URL hyperlinks
189 "weekdays=s", # Weekday names
190 "weekdaysabr=s",
191 # Abbreviated weekday names
192
193 ## API (only?) options
194 "noarg", # Just load code
195 "readdb", # Just read db
196
197 "v", # Version information
198 "help" # A brief usage message
199 );
200
201 ## Check for help/version options (nothing to do)
202 if ($opt{'help'}) { &usage(); return 0; }
203 if ($opt{'v'}) { &version(); return 0; }
204
205 ## Check std{in,out,err} options
206 DUP: {
207 $MhaStdin = \*STDIN;
208 #$MhaStdout = \*STDOUT;
209 #$MhaStderr = \*STDERR;
210 STDOUTERR: {
211 if (defined($opt{'stdout'}) && !ref($opt{'stdout'})) {
212 open(STDOUT, ">>$opt{'stdout'}") ||
213 die qq/ERROR: Unable to create "$opt{'stdout'}": $!\n/;
214 if ($opt{'stderr'} eq $opt{'stdout'}) {
215 open(STDERR, ">&STDOUT") ||
216 die qq/ERROR: Unable to dup STDOUT: $!\n/;
217 last STDOUTERR;
218 }
219 }
220 if (defined($opt{'stderr'}) && !ref($opt{'stderr'})) {
221 open(STDERR, ">>$opt{'stderr'}") ||
222 die qq/ERROR: Unable to create "$opt{'stderr'}": $!\n/;
223 }
224 }
225 if (defined($opt{'stdin'})) {
226 if (ref($opt{'stdin'})) {
227 $MhaStdin = $opt{'stdin'};
228 } else {
229 open(STDIN, "<$opt{'stdin'}") ||
230 die qq/ERROR: Unable to open "$opt{'stdin'}": $!\n/;
231 $MhaStdin = \*STDIN;
232 }
233 }
234 my $curfh = select(STDOUT); $| = 1;
235 select(STDERR); $| = 1;
236 select($curfh);
237 }
238
239 ## Initialize variables
240 require 'mhinit.pl'; &mhinit_vars();
241
242 ## These options have NO resource file equivalent.
243 $NoArg = $opt{'noarg'};
244 $ReadDB = $opt{'readdb'};
245
246 $ADD = $opt{'add'};
247 $RMM = $opt{'rmm'};
248 $SCAN = $opt{'scan'};
249 $QUIET = $opt{'quiet'};
250 $EDITIDX = $opt{'editidx'};
251 $ANNOTATE= $opt{'annotate'};
252 $AFS = $opt{'afs'};
253 if ($opt{'genidx'}) {
254 $IDXONLY = 1; $QUIET = 1; $ADD = 0;
255 } else {
256 $IDXONLY = 0;
257 }
258 if ($opt{'single'} && !$RMM && !$ANNOTATE) {
259 $SINGLE = 1; $QUIET = 1;
260 } else {
261 $SINGLE = 0;
262 }
263 $ReadDB = 1 if ($ADD || $EDITIDX || $RMM || $ANNOTATE || $SCAN ||
264 $IDXONLY);
265 $DoArchive = 1 if $opt{'archive'};
266 $DoArchive = 0 if $opt{'noarchive'};
267
268 my $dolock = !$NoArg && !$opt{'nolock'};
269
270 ## Check argv
271 unless (($#ARGV >= 0) || $ADD || $SINGLE || $EDITIDX || $SCAN ||
272 $IDXONLY || $ReadDB || !$DoArchive || $NoArg) {
273 usage();
274 return -1;
275 }
276
277 ## Require needed libraries
278 require 'ewhutil.pl';
279 require 'mhtime.pl';
280 require 'mhfile.pl';
281 require 'mhutil.pl';
282 require 'mhscan.pl' if $SCAN;
283 require 'mhsingle.pl' if $SINGLE;
284 require 'mhrmm.pl' if $RMM;
285 require 'mhnote.pl' if $ANNOTATE;
286
287 print STDOUT "This is MHonArc v$VERSION, Perl $] $^O\n" unless $QUIET;
288
289 ## Evaluate site local initialization
290 delete($INC{'mhasiteinit.pl'}); # force re-evaluation
291 eval { require 'mhasiteinit.pl'; }; # ignore status
292
293 ## Read default resource file
294 DEFRCFILE: {
295 if ($DefRcFile) {
296 read_fmt_file($DefRcFile);
297 last DEFRCFILE;
298 }
299 if (defined $ENV{'HOME'}) {
300 # check if in home directory
301 $tmp = join($DIRSEP, $ENV{'HOME'}, $DefRcName);
302 if (-e $tmp) {
303 read_fmt_file($tmp);
304 last DEFRCFILE;
305 }
306 }
307 local $_;
308 foreach (@INC) {
309 $tmp = join($DIRSEP, $_, $DefRcName);
310 if (-e $tmp) {
311 read_fmt_file($tmp);
312 last DEFRCFILE;
313 }
314 }
315 }
316
317 ## Grab a few options
318 @FMTFILE = @{$opt{'rcfile'}} if defined($opt{'rcfile'});
319 $LOCKTRIES = $opt{'locktries'} if defined($opt{'locktries'}) &&
320 ($opt{'locktries'} > 0);
321 $LOCKDELAY = $opt{'lockdelay'} if defined($opt{'lockdelay'}) &&
322 ($opt{'lockdelay'} > 0);
323 $FORCELOCK = $opt{'force'};
324
325 $LockMethod = &set_lock_mode($opt{'lockmethod'})
326 if defined($opt{'lockmethod'});
327
328 ## These options must be grabbed before reading the database file
329 ## since these options may tells us where the database file is.
330 $OUTDIR = $opt{'outdir'} if $opt{'outdir'};
331 if (!$NoArg && !($SCAN || $IDXONLY || $SINGLE)) {
332 die qq/ERROR: "$OUTDIR" does not exist\n/ unless -e $OUTDIR;
333 if (!$AFS) {
334 die qq/ERROR: "$OUTDIR" is not readable\n/ unless -r $OUTDIR;
335 die qq/ERROR: "$OUTDIR" is not writable\n/ unless -w $OUTDIR;
336 die qq/ERROR: "$OUTDIR" is not executable\n/ unless -x $OUTDIR;
337 }
338 }
339 $DBFILE = $opt{'dbfile'} if $opt{'dbfile'};
340
341 ## Create lock
342 $LOCKFILE = join($DIRSEP, $OUTDIR, $LOCKFILE);
343 if ($dolock && $DoArchive && !$SINGLE) {
344 if (!&$LockFunc($LOCKFILE, $LOCKTRIES, $LOCKDELAY, $FORCELOCK)) {
345 $! = 75; # EX_TEMPFAIL (for sendmail)
346 die("ERROR: Unable to lock $OUTDIR after $LOCKTRIES tries\n");
347 }
348 }
349
350 ## Check if we need to access database file
351 if ($ReadDB) {
352 $DBPathName = OSis_absolute_path($DBFILE) ?
353 $DBFILE : join($DIRSEP, $OUTDIR, $DBFILE);
354
355 ## Invoke preload callback
356 if (defined($CBDbPreLoad) && defined(&$CBDbPreLoad)) {
357 &$CBDbPreLoad($DBPathName);
358 }
359 if (-e $DBPathName) {
360 print STDOUT "Reading database ...\n" unless $QUIET;
361
362 ## Just perform a require. Delete %INC entry to force
363 ## evaluation.
364 delete $INC{$DBPathName};
365 require($DBPathName) ||
366 die("ERROR: Database read error of $DBPathName\n");
367
368 ## Check db version with program version
369 if ($VERSION ne $DbVERSION) {
370 warn "Warning: Database ($DbVERSION) != ",
371 "program ($VERSION) version.\n";
372 }
373
374 ## Check for 1.x archive, and update data as needed
375 if ($DbVERSION =~ /^1\./) {
376 print STDOUT "Updating database $DbVERSION data ...\n"
377 unless $QUIET;
378 &update_data_1_to_2();
379 &update_data_2_1_to_later();
380 &update_data_2_4_to_later();
381 }
382 ## Check for 2.[0-4] archive
383 if ($DbVERSION =~ /^2\.[0-4]\./) {
384 print STDOUT "Updating database $DbVERSION data ...\n"
385 unless $QUIET;
386 if ($DbVERSION =~ /^2\.[01]\./) {
387 &update_data_2_1_to_later();
388 }
389 &update_data_2_4_to_later();
390 }
391
392 ## Set %Follow here just incase it does not get recomputed
393 %Follow = %FollowOld;
394 }
395 if (!$IDXONLY) {
396 if ($#ARGV < 0) { $ADDSINGLE = 1; } # See if adding single mesg
397 else { $ADDSINGLE = 0; }
398 $ADD = $MhaStdin;
399 }
400 }
401 my($OldMULTIIDX) = $MULTIIDX;
402
403 ## Remove lock if db not going to be changed
404 if ($SCAN || $IDXONLY) {
405 &$UnlockFunc();
406 }
407
408 ## Clear thread flag if genidx, must be explicitly set
409 $THREAD = 0 if $IDXONLY;
410
411 ## Read resource file(s) (I initially used the term 'format file').
412 ## Look for resource in outdir unless existing according to
413 ## current value.
414 foreach (@FMTFILE) {
415 $_ = join($DIRSEP, $OUTDIR, $_) unless -e $_;
416 &read_fmt_file($_);
417 }
418
419 ## Check if extension for HTML files defined on the command-line
420 $HtmlExt = $opt{'htmlext'} if defined($opt{'htmlext'});
421
422 $RFC1522 = 1; # Always True
423
424 ## Other indexes resource files
425 if (defined($opt{'otherindex'})) {
426 my @array = ();
427 local($_);
428 foreach (@{$opt{'otherindex'}}) {
429 push(@array, split(/$PATHSEP/o, $_));
430 }
431 unshift(@OtherIdxs, @array);
432 }
433
434 ## Perl INC paths
435 if (defined($opt{'perlinc'})) {
436 my @array = ();
437 local($_);
438 foreach (@{$opt{'perlinc'}}) {
439 push(@array, split(/$PATHSEP/o, $_));
440 }
441 unshift(@PerlINC, @array);
442 }
443
444 @OtherIdxs = remove_dups(\@OtherIdxs);
445 @PerlINC = remove_dups(\@PerlINC);
446
447 ## Require mail parsing library
448 unshift(@INC, @PerlINC);
449 if (!$SCAN) {
450 # require readmail library
451 require 'readmail.pl' || die("ERROR: Unable to require readmail.pl\n");
452 $readmail::FormatHeaderFunc = \&mhonarc::htmlize_header;
453 $MHeadCnvFunc = \&readmail::MAILdecode_1522_str;
454 readmail::MAILset_alternative_prefs(@MIMEAltPrefs);
455 $IsDefault{'MIMEALTPREFS'} = !scalar(@MIMEAltPrefs);
456 }
457
458 ## Get other command-line options
459 $DBFILE = $opt{'dbfile'} if $opt{'dbfile'}; # Override db
460 $DBPathName = OSis_absolute_path($DBFILE) ?
461 $DBFILE : join($DIRSEP, $OUTDIR, $DBFILE);
462
463 $DOCURL = $opt{'docurl'} if $opt{'docurl'};
464 $FROM = $opt{'msgsep'} if $opt{'msgsep'};
465 $IDXPREFIX = $opt{'idxprefix'} if $opt{'idxprefix'};
466 $IDXSIZE = $opt{'idxsize'} if defined($opt{'idxsize'});
467 $IDXSIZE *= -1 if $IDXSIZE < 0;
468 $OUTDIR = $opt{'outdir'} if $opt{'outdir'}; # Override db
469 $MAILTOURL = $opt{'mailtourl'} if $opt{'mailtourl'};
470 $MAXSIZE = $opt{'maxsize'} if defined($opt{'maxsize'});
471 $MAXSIZE = 0 if $MAXSIZE < 0;
472 $MHPATTERN = $opt{'mhpattern'} if $opt{'mhpattern'};
473 $TIDXPREFIX = $opt{'tidxprefix'} if $opt{'tidxprefix'};
474 $TITLE = $opt{'title'} if $opt{'title'};
475 $TLEVELS = $opt{'tlevels'} if $opt{'tlevels'};
476 $TTITLE = $opt{'ttitle'} if $opt{'ttitle'};
477 $MsgPrefix = $opt{'msgprefix'} if defined($opt{'msgprefix'});
478 $GzipExe = $opt{'gzipexe'} if $opt{'gzipexe'};
479 $VarExp = $opt{'varregex'} if $opt{'varregex'} &&
480 ($opt{'varregex'} =~ /\S/);
481 $TSLICELEVELS = $opt{'tslicelevels'} if $opt{'tslicelevels'};
482
483 $IDXNAME = $opt{'idxfname'} || $IDXNAME || $ENV{'M2H_IDXFNAME'} ||
484 "maillist.$HtmlExt";
485 $TIDXNAME = $opt{'tidxfname'} || $TIDXNAME || $ENV{'M2H_TIDXFNAME'} ||
486 "threads.$HtmlExt";
487
488 $ExpireDate = $opt{'expiredate'} if $opt{'expiredate'};
489 $ExpireTime = $opt{'expireage'} if $opt{'expireage'};
490 $ExpireTime *= -1 if $ExpireTime < 0;
491
492 $GMTDateFmt = $opt{'gmtdatefmt'} if $opt{'gmtdatefmt'};
493 $LocalDateFmt = $opt{'localdatefmt'} if $opt{'localdatefmt'};
494
495 $AddressModify = $opt{'addressmodifycode'} if $opt{'addressmodifycode'};
496 $SubArtRxp = $opt{'subjectarticlerxp'} if $opt{'subjectarticlerxp'};
497 $SubReplyRxp = $opt{'subjectreplyrxp'} if $opt{'subjectreplyrxp'};
498 $SubStripCode = $opt{'subjectstripcode'} if $opt{'subjectstripcode'};
499 $MsgExcFilter = $opt{'msgexcfilter'} if defined($opt{'msgexcfilter'});
500
501 $NoSubjectTxt = $opt{'nosubjecttxt'} if $opt{'nosubjecttxt'};
502
503 $IdxPageNum = $opt{'pagenum'} if defined($opt{'pagenum'});
504
505 ## Determine location of message note files
506 $NoteDir = $opt{'notedir'} if $opt{'notedir'};
507
508 ## See if note text defined on command-line
509 if (defined $opt{'notetext'}) {
510 $NoteText = join(" ", @{$opt{'notetext'}});
511 } else {
512 $NoteText = undef;
513 }
514
515 ## Parse any rc variable definition from command-line
516 if (defined($opt{'definevar'})) {
517 my @array = ();
518 foreach (@{$opt{'definevar'}}) {
519 push(@array, &parse_vardef_str($_));
520 }
521 %CustomRcVars = (%CustomRcVars, @array);
522 }
523
524 $CONLEN = 1 if $opt{'conlen'};
525 $CONLEN = 0 if $opt{'noconlen'};
526 $MAIN = 1 if $opt{'main'};
527 $MAIN = 0 if $opt{'nomain'};
528 $MODTIME = 1 if $opt{'modtime'};
529 $MODTIME = 0 if $opt{'nomodtime'};
530 $MULTIIDX = 1 if $opt{'multipg'};
531 $MULTIIDX = 0 if $opt{'nomultipg'};
532 $NODOC = 0 if $opt{'doc'};
533 $NODOC = 1 if $opt{'nodoc'};
534 $NOMAILTO = 1 if $opt{'nomailto'};
535 $NONEWS = 0 if $opt{'news'};
536 $NONEWS = 1 if $opt{'nonews'};
537 $NOURL = 0 if $opt{'url'};
538 $NOURL = 1 if $opt{'nourl'};
539 $SLOW = 1 if $opt{'savemem'};
540 $THREAD = 1 if $opt{'thread'};
541 $THREAD = 0 if $opt{'nothread'};
542 $TREVERSE = 1 if $opt{'treverse'};
543 $TREVERSE = 0 if $opt{'notreverse'};
544 $DoFolRefs = 1 if $opt{'folrefs'};
545 $DoFolRefs = 0 if $opt{'nofolrefs'};
546 $GzipFiles = 1 if $opt{'gzipfiles'};
547 $GzipFiles = 0 if $opt{'nogzipfiles'};
548 $GzipLinks = 1 if $opt{'gziplinks'};
549 $GzipLinks = 0 if $opt{'nogziplinks'};
550 $NoMsgPgs = 0 if $opt{'msgpgs'};
551 $NoMsgPgs = 1 if $opt{'nomsgpgs'};
552 $SaveRsrcs = 1 if $opt{'saveresources'};
553 $SaveRsrcs = 0 if $opt{'nosaveresources'};
554 $SpamMode = 1 if $opt{'spammode'};
555 $SpamMode = 0 if $opt{'nospammode'};
556 $KeepOnRmm = 1 if $opt{'keeponrmm'};
557 $KeepOnRmm = 0 if $opt{'nokeeponrmm'};
558
559 $CheckNoArchive = 1 if $opt{'checknoarchive'};
560 $CheckNoArchive = 0 if $opt{'nochecknoarchive'};
561 $POSIXstrftime = 1 if $opt{'posixstrftime'};
562 $POSIXstrftime = 0 if $opt{'noposixstrftime'};
563
564 $DecodeHeads = 1 if $opt{'decodeheads'};
565 $DecodeHeads = 0 if $opt{'nodecodeheads'};
566 $readmail::DecodeHeader = $DecodeHeads;
567
568 ## Clear main flag if genidx and thread specified
569 $MAIN = 0 if $IDXONLY && $THREAD;
570
571 @DateFields = split(/[:;]/, $opt{'datefields'}) if $opt{'datefields'};
572 @FromFields = split(/[:;]/, $opt{'fromfields'}) if $opt{'fromfields'};
573 foreach (@FromFields) { s/\s//g; tr/A-Z/a-z/; }
574
575 ($TSliceNBefore, $TSliceNAfter, $TSliceInclusive) =
576 split(/[:;]/, $opt{'tslice'}) if $opt{'tslice'};
577
578 @Months = split(/:/, $opt{'months'}) if defined($opt{'months'});
579 @months = split(/:/, $opt{'monthsabr'}) if defined($opt{'monthsabr'});
580 @Weekdays = split(/:/, $opt{'weekdays'}) if defined($opt{'weekdays'});
581 @weekdays = split(/:/, $opt{'weekdaysabr'}) if defined($opt{'weekdaysabr'});
582
583 $MULTIIDX = 0 if !$IDXSIZE;
584
585 ## Set umask
586 if ($UNIX) {
587 $UMASK = $opt{'umask'} if defined($opt{'umask'});
588 eval { umask oct($UMASK); };
589 }
590
591 ## Get sort method
592 $AUTHSORT = 1 if $opt{'authsort'};
593 $AUTHSORT = 0 if $opt{'noauthsort'};
594 $SUBSORT = 1 if $opt{'subsort'};
595 $SUBSORT = 0 if $opt{'nosubsort'};
596 $NOSORT = 1 if $opt{'nosort'};
597 $NOSORT = 0 if $opt{'sort'};
598 $REVSORT = 1 if $opt{'reverse'};
599 $REVSORT = 0 if $opt{'noreverse'};
600 if ($NOSORT) {
601 $SUBSORT = 0; $AUTHSORT = 0;
602 } elsif ($SUBSORT) {
603 $AUTHSORT = 0;
604 }
605
606 ## Check for thread listing order
607 $TSUBSORT = 1 if $opt{'tsubsort'};
608 $TSUBSORT = 0 if $opt{'notsubsort'};
609 $TNOSORT = 1 if $opt{'notsort'};
610 $TNOSORT = 0 if $opt{'tsort'};
611 $TREVERSE = 1 if $opt{'treverse'};
612 $TREVERSE = 0 if $opt{'notreverse'};
613 if ($TNOSORT) {
614 $TSUBSORT = 0;
615 }
616 $NoSubjectThreads = 1 if $opt{'nosubjectthreads'};
617 $NoSubjectThreads = 0 if $opt{'subjectthreads'};
618
619 ## Check if all messages must be updated (this has been simplified;
620 ## any serious change should be done via editidx).
621 if ($EDITIDX || ($OldMULTIIDX != $MULTIIDX)) {
622 $UPDATE_ALL = 1;
623 } else {
624 $UPDATE_ALL = 0;
625 }
626
627 ## Set date names
628 &set_date_names(\@weekdays, \@Weekdays, \@months, \@Months);
629
630 ## Set %Zone with user-specified timezones
631 while (($zone, $offset) = each(%ZoneUD)) {
632 $Zone{$zone} = $offset;
633 }
634
635 ## Require some more libaries
636 require 'mhidxrc.pl'; &mhidxrc_set_vars();
637 require 'mhdysub.pl'; &create_routines();
638 require 'mhrcvars.pl';
639 require 'mhindex.pl';
640 require 'mhthread.pl';
641 require 'mhdb.pl' unless $SCAN || $IDXONLY || !$DoArchive;
642
643 ## Load text clipping function
644 if (defined($TextClipSrc)) {
645 eval { require $TextClipSrc; };
646 if ($@) { warn qq/Warning: $@\n/; }
647 }
648 if (!defined($TextClipFunc) || !defined(&$TextClipFunc)) {
649 $TextClipFunc = \&clip_text;
650 $TextClipSrc = undef;
651 $IsDefault{'TEXTCLIPFUNC'} = 1;
652 } else {
653 $IsDefault{'TEXTCLIPFUNC'} = 0;
654 }
655
656 ## Predefine %Index2TLoc in case of message deletion
657 if (@TListOrder) {
658 @Index2TLoc{@TListOrder} = (0 .. $#TListOrder);
659 }
660
661 ## Define %Index2MsgId hash
662 foreach (keys %MsgId) {
663 $Index2MsgId{$MsgId{$_}} = $_;
664 }
665
666 ## Set $ExpireDateTime from $ExpireDate
667 if ($ExpireDate) {
668 my @array = ();
669 if (@array = &parse_date($ExpireDate)) {
670 $ExpireDateTime = &get_time_from_date(@array[1..$#array]);
671 } else {
672 warn qq|Warning: Unable to parse EXPIREDATE, "$ExpireDate"\n|;
673 }
674 }
675
676 ## Get highest message number
677 if ($ADD) {
678 $LastMsgNum = &get_last_msg_num();
679 } else {
680 $LastMsgNum = -1;
681 }
682
683 ## Delete bogus empty entries in hashes due to bug in earlier
684 ## versions to avoid any future problems.
685 delete($IndexNum{''});
686 delete($Subject{''});
687 delete($From{''});
688 delete($MsgId{''});
689 delete($FollowOld{''});
690 delete($ContentType{''});
691 delete($Refs{''});
692
693 # update DOCURL if default old value
694 if ($DOCURL eq 'http://www.oac.uci.edu/indiv/ehood/mhonarc.html') {
695 $DOCURL = 'http://www.mhonarc.org/';
696 }
697
698 ## Check if printing process time
699 $TIME = $opt{'time'};
700
701 1;
702}
703
704##---------------------------------------------------------------------------
705## Version routine
706##
707sub version {
708 select(STDOUT);
709 print $VINFO;
710}
711
712##---------------------------------------------------------------------------
713## Usage routine
714##
715sub usage {
716 require 'mhusage.pl';
717 &mhusage();
718}
719
720##---------------------------------------------------------------------------
721## read_fmt_file() requires the library with the resource file
722## read subroutine and calls the routine.
723##
724sub read_fmt_file {
725 require 'mhrcfile.pl';
726 &read_resource_file; # implicit passing of @_
727}
728
729##---------------------------------------------------------------------------
730## Routine to update 1.x data structures to 2.0.
731##
732sub update_data_1_to_2 {
733 local(%EntName2Char) = (
734 'lt', '<',
735 'gt', '>',
736 'amp', '&',
737 );
738 #--------------------------------------
739 sub entname_to_char {
740 my($name) = shift;
741 my($ret) = $EntName2Char{$name};
742 if (!$ret) {
743 $ret = "&$name;";
744 }
745 $ret;
746 }
747 #--------------------------------------
748 my($index);
749 foreach $index (keys %From) {
750 $From{$index} =~ s/\&([\w\-.]+);/&entname_to_char($1)/ge;
751 }
752 foreach $index (keys %Subject) {
753 $Subject{$index} =~ s/\&([\w\-.]+);/&entname_to_char($1)/ge;
754 }
755 delete $IndexNum{''};
756 $TLITXT = '<li>' . $TLITXT unless ($TLITXT) && ($TLITXT =~ /<li>/i);
757 $THEAD .= "<ul>\n" unless ($THEAD) && ($THEAD =~ m%<ul>\s*$%i);
758 $TFOOT = "</ul>\n" unless ($TFOOT) && ($TFOOT =~ m%^\s*</ul>%i);
759}
760
761##---------------------------------------------------------------------------
762## Update 2.1, or earlier, data.
763##
764sub update_data_2_1_to_later {
765 # we can preserve filter arguments
766 if (defined(%main::MIMEFiltersArgs)) {
767 warn qq/ preserving MIMEARGS...\n/;
768 %readmail::MIMEFiltersArgs = %main::MIMEFiltersArgs;
769 $IsDefault{'MIMEARGS'} = 0;
770 }
771}
772
773##---------------------------------------------------------------------------
774## Update 2.4, or earlier, data.
775##
776sub update_data_2_4_to_later {
777 # convert Perl 4 style data to Perl 5 style
778 my($index, $value);
779 while (($index, $value) = each(%Refs)) {
780 next if ref($value);
781 $Refs{$index} = [ split(/$X/o, $value) ];
782 }
783 while (($index, $value) = each(%FollowOld)) {
784 next if ref($value);
785 $FollowOld{$index} = [ split(/$bs/o, $value) ];
786 }
787 while (($index, $value) = each(%Derived)) {
788 next if ref($value);
789 $Derived{$index} = [ split(/$X/o, $value) ];
790 }
791}
792
793##---------------------------------------------------------------------------
7941;