home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume28
/
bmw-5
/
part01
/
digestify
< prev
next >
Wrap
Text File
|
1994-07-09
|
5KB
|
217 lines
#! /usr/bin/perl
# Digestify -- accept a mail message on standard input. Strip the headers
# and cat into the digest file. Build the digest table of contents file
# as well.
$USAGE = "$0 <listname>\n";
if ($#ARGV != 0) { die ("$USAGE"); }
$LISTNAME = $ARGV[0];
$LISTNAME =~ tr/A-Z/a-z/; # Convert everything to lower case for now.
%GLOBALS = ();
## We need to set the hostname. You this is done by querying hostname and
## domainname. You can override this here or set your FQDN global explicitly
## in the bmw.cf file.
$HOSTNAME = `hostname`; chop($HOSTNAME);
$DOMAINNAME = `domainname`; chop($DOMAINNAME);
## Path to bmw.cf - CHANGE THIS FOR YOUR SYSTEM
#$BMWCF = "/etc/bmw.cf";
$BMWCF = "/home/bmw/bmw.cf";
## Process the config file and learn about all the globals.
## FORMAT OF CONFIG FILE:
## Each line of the config file should have the format
## <globalname> = <value>
## for example,
## BASEDIR = /usr/local/lib/bmw
##
## I now set the defaults. You should override these in your bmw.cf file.
##
$GLOBALS{'SENDMAIL'} = "/usr/lib/sendmail";
$GLOBALS{'SENDMAILOPTS'} = "";
$GLOBALS{'ENCODE'} = "/usr/bin/uuencode";
$GLOBALS{'COMPRESS'} = "/bin/gzip";
$GLOBALS{'COMPSUFFIX'} = ".gz";
$GLOBALS{'ARCDIR'} = "/home/ftp/pub/lists";
$GLOBALS{'ARCOWNER'} = "ftp";
$GLOBALS{'OWNER'} = "postmaster";
$GLOBALS{'DEBUG'} = 0;
$GLOBALS{'LOG'} = 0;
$GLOBALS{'MAXGETS'} = 5;
$GLOBALS{'PREFERFTP'} = 0;
$GLOBALS{'TRACE'} = 0;
$GLOBALS{'BASEDIR'} = "/usr/local/lib/bmw";
$GLOBALS{'FQDN'} = $HOSTNAME . "." . $DOMAINNAME;
$GLOBALS{'DIGEST'} = 0;
$GLOBALS{'TMPDIR'} = "/var/tmp";
$GLOBALS{'USER'} = "bmw";
$GLOBALS{'GROUP'} = "bin";
@VALIDGLOBALS = ("SENDMAIL", "SENDMAILOPTS", "TMPDIR", "ENCODE",
"COMPRESS", "COMPSUFFIX", "ARCDIR", "ARCOWNER",
"OWNER", "DEBUG", "LOG", "MAXGETS", "PREFERFTP",
"TRACE", "BASEDIR", "FQDN", "DIGEST", "USER", "GROUP");
sub validGlobal {
## Determine if the string is a valid global reference.
local($s) = @_;
local($i);
for ($i=0; $i<=$#VALIDGLOBALS; $i++) {
if ($s eq $VALIDGLOBALS[$i]) { return 1; }
}
return 0;
}
## Load the globals from the cf file.
if (-e $BMWCF) {
local($lno) = 0;
local(@LINE);
open(CF, "<$BMWCF") || die "Cannot open $BMWCF: $!\n";
while (<CF>) {
$lno++;
chop;
tr/\t //d;
@LINE = split("=");
if (!$LINE[0]) { die "ERROR in $BMWCF line $lno; $_\n"; }
$LINE[0] =~ tr/a-z/A-Z/;
if (!&validGlobal($LINE[0])) {
die "ERROR in $BMWCF line $lno; Unknown global \"$LINE[0]\"\n";
}
## Good. We have a valid global
$GLOBALS{$LINE[0]} = $LINE[1];
}
}
else {
die "$BMWCF does not exist!\n";
}
if ($GLOBALS{'DEBUG'}) {
local($key);
foreach $key (keys %GLOBALS) {
print "$key = $GLOBALS{$key}",$LF;
}
}
## Internal global values. Do not fiddle with these without good reason.
$VERSION = "5.0";
$LISTDIR = $GLOBALS{'BASEDIR'} . "/$LISTNAME";
$DIGESTFILE = "$LISTDIR/digest";
$TOCFILE = "$LISTDIR/digesttoc";
$LOGFILE = "$LISTDIR/log";
$MESSAGE = "$LISTDIR/message";
$HELP = "$LISTDIR/help";
$WDIR = ""; # working directory suffix for gets
$TMPFILE = $GLOBALS{'TMPDIR'} . "/bmw$$";
$REPLYFILE = "$TMPFILE.reply";
$TMPLOGFILE = "$TMPFILE.log";
$LISTOWNER = "$LISTNAME-owner";
$LISTREQUEST = "$LISTNAME-request";
@ERRORS = ();
%LOCKS = ();
##
## Exit routines. These make sure everything is cleaned up.
##
sub finish {
local($rc) = @_;
local($i);
system("rm -f $TMPFILE");
if ($#ERRORS > -1) {
open(T, ">$TMPFILE");
print T "Subject: Errors from $LISTREQUEST\n";
print T "From: $LISTOWNER\n";
print T "To: $LISTOWNER\n\n";
for ($i = 0; $i <= $#ERRORS; $i++) {
print T $ERRORS[$i],$LF;
}
close(T);
system("cat $TMPFILE | $GLOBALS{'SENDMAIL'} \'$LISTOWNER\'");
system("rm -f $TMPFILE")
}
exit($rc);
}
sub DIE {
local($msg) = @_;
print STDERR "$msg",$LF;
$ERRORS[$#ERRORS+1] = $msg;
local($key);
foreach $key (keys %LOCKS) {
system("rm -f $key");
}
&finish(-1);
}
# Test for things that must exist.
&DIE("$LISTDIR does not exist!\n") if (! -d $LISTDIR);
$FROM = "";
$SUBJECT = "";
$MID = "";
$DATE = `date`; chop($DATE);
if (! -e $DIGESTFILE)
{
system("touch $DIGESTFILE");
chown $GLOBALS{'USER'}, $GLOBALS{'GROUP'}, $DIGESTFILE;
chmod 0664 , $DIGESTFILE;
}
shift;
open(TF,">>$DIGESTFILE") || &DIE("Could not open $DIGESTFILE: $!\n");
$HEADERS = 1;
$INFROM = 0;
while (<>)
{
if ($HEADERS) {
if ($INFROM && /^\s/) {
local($morefrom);
$morefrom = $1 if m/^\s*(.*)\n/;
$FROM = $FROM . $morefrom . "\n";
}
else {
$INFROM = 0;
if (/^Subject:/) { $SUBJECT = $_; }
if (/^From:/) { $FROM = $_; }
if (/^Message-Id:/) { $MID = $_; }
if ($_ eq "\n") {
## Blank line ends headers.
$HEADERS = 0;
print TF "\n" . $SUBJECT;
print TF $FROM;
print TF "Date: " . $DATE . "\n";
print TF $MID;
print TF "Reply-To: $LISTNAME@$GLOBALS{'FQDN'}\n\n";
}
}
}
else {
print TF $_;
}
}
close(TF);
&finish();