#!/usr/bin/perl
#
# list-archive.pl
# Program for archiving mailing lists using Hypermail
# Written by Shane Wegner <shane@cm.nu>
# Last modified: 2000-03-07
#
use Getopt::Long;
# Required programs
$hypermail = "/usr/bin/hypermail";
$bzip2 = "/usr/bin/bzip2";
# Internal variables
($_,$_,$_,$_,$month,$year) = localtime;
$month++;
$year += 1900;
$month = "0$month" if (length($month) == 1);
$home = (getpwuid($<))[7];
&do_cmdline;
die("--list not specified.\n") if (!$listname);
if ($rearch && -e "$home/lists/$listname-$rearch.bz2")
{
system("rm -rf $home/public_html/lists/$listname-$rearch");
system("$bzip2 -d -c $home/lists/$listname-$rearch.bz2 ".
"|$hypermail -c $home/lists/$listname.config ".
"-d $home/public_html/lists/$listname-$rearch -i") if (!$noarch);
} elsif ($nodate)
{
system("$hypermail -c $home/lists/$listname.config ".
"-d $home/public_html/lists/$listname -m $home/lists/$listname")
if (!$noarch);
} else {
if ( ! -d "$home/public_html/lists/$listname-$year-$month") {
$month--;
$month = "0$month" if (length($month) == 1);
if (!$month)
{
$month = 12;
$year--;
} # endif
system("$hypermail -c $home/lists/$listname.config ".
"-d $home/public_html/lists/$listname-$year-$month -m $home/lists/$listname")
if (!$noarch);
rename("$home/lists/$listname","$home/lists/$listname-$year-$month");
system("$bzip2 $home/lists/$listname-$year-$month");
$month++;
if ($month==13) {
$month = "01";
$year++;
} # endif
mkdir("$home/public_html/lists/$listname-$year-$month", 0711) ||
die "mkdir: $!\n";
} # endif
system("$hypermail -c $home/lists/$listname.config ".
"-d $home/public_html/lists/$listname-$year-$month -m $home/lists/$listname")
if (!$noarch && -e "$home/lists/$listname");
}

sub do_cmdline {
local(%options);
Getopt::Long::config("pass_through", "no_ignore_case");
GetOptions(\%options,"list:s","rearch:s","nodate","noarch");
foreach (keys(%options)) {
switch: {
/^list$/ && do {
$listname = $options{$_};
last switch;
}; /^rearch$/ && do {
$rearch = $options{$_};
last switch;
}; /^nodate$/ && do {
$nodate = 1;
last switch;
}; /^noarch$/ && do {
$noarch = 1;
last switch;
};
die("Invalid Option: $_\n");
} # end switch
} # end foreach
}

