#!/usr/bin/perl
#
# mlist2html.pl converted mlist2html to perl script
# by nob@makioka.y-min.or.jp 1997.3.29
# easy lock system is installed
#
#
$mlist_name = $ARGV[0];
#
if ($mlist_name eq "") {
print "Usage : mlist2html ml-name \n";
exit;
}
#
# where to archive
# this should be end /
#
$mlists_path = "/home/nob/html/ML/";
#
# this directory should be make manually
#
$mlist_path = $mlists_path . $mlist_name ;
#
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
#
# lock by /tmp/$mlist_name.lock
# if /tmp/$mlist_name.lock is exist wait 30 sec
#
until (! -e "/tmp/$mlist_name.lock") {
print "now waiting \n";
sleep(30);
}
#
# make lock file
open(LOCK,"> /tmp/$mlist_name.lock");
print LOCK "locked";
close(LOCK);
#
#
#
#
$akt_year = '19' . $year;
#
$mon = $mon+1 ;
$akt_month = substr('0'.$mon, -2);
#
$datum = $akt_year . $akt_month . substr('0'.$mday,-2);
$i_datum = $akt_year . $akt_month;
#
$mon_path = $mlist_path . '/' . $i_datum ;
#
@monat=(dummy,January,February,March,April,May,June,July,August,September,October,Nobember,December);
#
#
if (! -d $mlist_path ){
mkdir($mlist_path,0755) || die "cannot mkdir $mlist_path \n";
}
#
#
# if there is no index file for the current month
# create a directory for the current month and
# create a new index of old months that are still available
#
#
if (! -d $mon_path ) {
mkdir($mon_path,0755) || die "cannot mkdir $mon_path \n";
#
open (OLDM,"> $mlist_path/oldmonths.html") ;
print OLDM "
\n";
close(OLDM);
}
#
#
#
# initialize the fragment number for this day
#
if (! -e "$mlist_path/$datum.fragid") {
unlink(<$mlist_path/*.fragid>);
$fragid = 0;
}
else {
open (FRAGID,"$mlist_path/$datum.fragid");
while() {
chop ;
# print "read fro fragid file = $_ \n";
$fragid = $_+1;
}
close(FRAGID)
}
#
open (FRAGID,"> $mlist_path/$datum.fragid");
print FRAGID "$fragid\n";
close(FRAGID);
#
#
#
# if there is already a file for this day (had another mail today)
# move it aside so we can append it to the current message
# this is for the reverse-date order
#
if ( -e "$mlist_path/$i_datum/$datum.html") {
rename("$mlist_path/$i_datum/$datum.html","$mlist_path/$i_datum/$datum.html.old");
}
#
#
#
# if there is already a file for this month
# move it aside so we can append it to the newest entry
# this is for the reverse-date order
#
if ( -e "$mlist_path/$i_datum.list") {
rename("$mlist_path/$i_datum.list","$mlist_path/$i_datum.list.old");
}
else {
unlink (<"$mlist_path/*.list">);
}
#
# $datum = $datum;
# $i_datum= $i_datum;
# $akt_month= $akt_month;
# $akt_year= $akt_year;
$fragmentno = $fragid;
$in_header = 1;
$fromstr = "From: [none given]";
$datestr = "Date: [none given]";
$messageidstr = "Message-Id: [none given]";
$subjectstr = "Subject: [none given]";
#
#
# change all special characters to HTML syntax
#
#
open (NEWDATUM,"> $mlist_path/$i_datum/$datum.html");
select (NEWDATUM);
#
print " \n";
print "\n";
while () {
chop;
s/\&/\&/g;
s/\"/\"/g;
s/\</g;
s/>/\>/g;
#
if (/^$/) {
if ($in_header) {
print "$fromstr \n" ;
print "$datestr \n" ;
print "$subjectstr \n" ;
print "$messageidstr \n" ;
print "
\n";
}
$in_header = 0;
}
#
if (/^From: /){ $fromstr = $_ ;}
if (/^Date: /){ $datestr = $_ ;}
if (/^Subject: /) {$subjectstr = $_ ; }
if (/^Message-id: /i){$messageidstr = $_ ;}
if (! $in_header){
# decode URL to html
# s#http://(.*)/#http://\1# ;
# s#http://(.*)html#http://\1html# ;
print $_ . "\n" ;
}
}
print "
\n\n";
#
#
# if we already had one, append it for reverse-date order
#
if ( -e "$mlist_path/$i_datum/$datum.html.old") {
open (NEWDATUM,">> $mlist_path/$i_datum/$datum.html");
open (OLDDATUM,"$mlist_path/$i_datum/$datum.html.old");
while () {
print NEWDATUM $_;
}
unlink ("$mlist_path/$i_datum/$datum.html.old");
}
#
close(NEWDATUM);
close(OLDTATUM);
#
#
#
#
#
open (NEWLIST,"> $mlist_path/$i_datum.list");
select (NEWLIST);
#
$subjectstr = substr($subjectstr,9);
$fromstr = substr($fromstr,6);
$datestr = substr($datestr,6);
print "";
print "$subjectstr$datestr $fromstr\n";
#
#
if ( -e "$mlist_path/$i_datum.list.old") {
open (NEWLIST,">> $mlist_path/$i_datum.list");
open (OLDLIST,"$mlist_path/$i_datum.list.old");
while () {
print NEWLIST $_;
}
unlink ("$mlist_path/$i_datum.list.old");
}
#
close(NEWLIST);
close(OLDLIST);
#
#
# put it all together an create a file listing all entries for
# this month (and a list of previous months)
#
open (NEWHTML,"> $mlist_path/$i_datum-month.html");
open (NEWLIST,"$mlist_path/$i_datum.list");
open (OLDM,"$mlist_path/oldmonths.html");
#
select(NEWHTML);
#
print "\n";
print "Archive: $mlist_name mailing list\n";
print "\n";
print "\n";
print "Archive: $mlist_name mailing list
\n";
print "$monat[$akt_month] $akt_year
\n";
print "\n";
while (){
print $_ ;
}
print "
\n";
print "Archive of previous months:
\n";
while (){
print $_ ;
}
print "\n";
#
#
close(NEWHTML); # 199703-month.html
close(NEWLIST); # 199703.list
close(OLDM); # oldmonths.html
#
#
#
# link it to list-name.html
#
unlink("$mlist_path/$mlist_name.html");
link("$mlist_path/$i_datum-month.html","$mlist_path/$mlist_name.html");
#
#
# unlock by remobe /tmp/$mlist_name.lock
unlink("/tmp/$mlist_name.lock");
#
#
#
#