#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#               "End of shell archive."
# Contents:  archive
# Wrapped by brent@mycroft on Sat Feb 19 17:56:10 1994
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'archive' -a "${1}" != "-c" ; then
 echo shar: Will not clobber existing file \"'archive'\"
else
echo shar: Extracting \"'archive'\" \(4076 characters\)
sed "s/^X//" >'archive' <<'END_OF_FILE'
X#!/usr/local/bin/perl
X
X# Copyright 1993, D. Brent Chapman.  All Rights Reserved.  For use by
X# permission only.
X#
X# $Source: /mycroft/brent/majordomo/RCS/archive,v $
X# $Revision: 1.2 $
X# $Date: 1993/11/09 07:17:05 $
X# $Author: brent $
X# $State: Exp $
X#
X# $Locker:  $
X#
X# archive -f <archive> {-u|-a} [-d|-m|-y] [file ...]
X#      -f <archive> REQUIRED; specifies base file name for archive
X#      -u      Input is a UNIX archive (separated by "From " lines) to split
X#      -a      Input is a message to append to archive
X#      -d      Archive file is <archive>.YYMMDD
X#      -m      Archive file is <archive>.YYMM
X#      -y      Archive file is <archive>.YY
X# Exactly one of "-u" or "-a" must be specified.
X# At most one of "-d", "-m", or "-y" may be specified; if none is
X#   specified, archive name is simply <archive>
X#
X# An example of using "archive" to split an existing UNIX-style archive
X# named "my-list.archive" into by-day archive files named "my-list.YYMMDD":
X#
X#      archive -f my-list -d -u my-list.archive
X#
X# A sample /etc/aliases file entry to use "archive" add each incoming message
X# to a "my-list.YYMM" file in the "/usr/local/mail/lists/my-list.archive"
X# directory:
X#
X#      my-list-archive: "|/usr/local/mail/majordomo/wrapper archive
X#              -f /usr/local/mail/lists/my-list.archive/my-list
X#              -m -a"
X
X# set our path explicitly
X$ENV{'PATH'} = "/bin:/usr/bin:/usr/ucb";
X
X# What shall we use for temporary files?
X$tmp = "/tmp/majordomo.$$";
X
X# Read and execute the .cf file
X$cf = $ENV{"MAJORDOMO_CF"} || "/etc/majordomo.cf";
if ($ARGV[0] eq "-C") {
X    $cf = $ARGV[1];
X    shift(@ARGV);
X    shift(@ARGV);
X}
if (! -r $cf) {
X    die("$cf not readable; stopped");
X}
eval(`cat $cf`);
X
X# All these should be in the standard PERL library
unshift(@INC, $homedir);
require "ctime.pl";             # To get MoY definitions for month abbrevs
require "majordomo_version.pl"; # What version of Majordomo is this?
require "majordomo.pl";         # all sorts of general-purpose Majordomo subs
require "shlock.pl";            # NNTP-style file locking
X
X# Here's where the fun begins...
X
require "getopts.pl";
X
X$m = 1;
foreach (@ctime'MoY) {
X    $MoY{$_} = $m++;
X}
X
X$usage = "Usage: $0 -f <file> {-u|-a} [-d|-m|-y] [file ...]";
X
X&Getopts("f:uadmy") || die("$usage\nStopped");
X
if (!defined($opt_f)) {
X    print STDERR "'-f <list>' required\n$usage\n";
X    exit 1;
X}
X
if (defined($opt_a)) { $mutex++; }
if (defined($opt_u)) { $mutex++; }
if ($mutex != 1) {
X    print STDERR "Either '-a' or '-u' required\n$usage\n";
X    exit 2;
X}
X
X$mutex = 0;
X
if (defined($opt_d)) { $mutex++; }
if (defined($opt_m)) { $mutex++; }
if (defined($opt_y)) { $mutex++; }
if ($mutex > 1) {
X    print STDERR "Only one of '-d', '-m', or '-y' allowed\n$usage\n";
X    exit 3;
X}
X
if (defined($opt_a)) {
X    ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
X       localtime(time);
X    &open_archive(FILE, $year, $mon + 1, $mday);
X}
X
while (<>) {
X    if (/^From\s/) {
X       if (/^From\s+\S+\s+(Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+\d\d?\s+\d\d?:\d\d:\d\d\s+\d{2,4}\s*$/i) {
X           if (defined($opt_u)) {
X               if (defined($is_open)) {
X                   print FILE "\n";
X                   &lclose(FILE);
X               }
X               &open_archive_unix(FILE, $_);
X           }
X           print FILE "$_";
X       } else {
X           print FILE ">$_";
X       }
X    } else {
X       print FILE $_;
X    }
X}
X
print FILE "\n";
X&lclose(FILE);
X
sub open_archive_unix {
X    local($FH) = shift;
X    local($from) = shift;
X    local($junk, $addr, $dow, $moy, $dom, $time, $year, @rest);
X
X    ($junk, $addr, $dow, $moy, $dom, $time, $year, @rest) = split(/\s+/,$from);
X    &open_archive($FH, $year % 100, $MoY{$moy}, $mday);
X}
X
sub open_archive {
X    local($FH) = shift;
X    local($year) = shift;
X    local($mon) = shift;
X    local($mday) = shift;
X    local($suffix);
X
X    if (defined($opt_y)) {
X       $suffix = sprintf(".%02d", $year % 100);
X    }
X    if (defined($opt_m)) {
X       $suffix = sprintf(".%02d%02d", $year % 100, $mon);
X    }
X    if (defined($opt_d)) {
X       $suffix = sprintf(".%02d%02d%02d", $year % 100, $mon, $mday);
X    }
X
X    &lopen($FH, ">>", "$opt_f$suffix") ||
X       die("Can't append to $opt_f$suffix: $!");
X    $is_open = 1;
X}
END_OF_FILE
if test 4076 -ne `wc -c <'archive'`; then
   echo shar: \"'archive'\" unpacked with wrong size!
fi
chmod +x 'archive'
# end of 'archive'
fi
echo shar: End of shell archive.
exit 0