#!/usr/bin/perl

use Text::Wrap;

system("cal > /usr/local/bin/month");
open (IN, "/usr/local/bin/month");

$month = <IN>;

chomp $month;
$month =~ s/\W+(\w+)\W(.*)/$2-$1/g;
$munth = $1;

close IN;

$url = "http://phobos.serve.com/pipermail/philly_ambient/$month";
$path = "/home/mailman/archives/private/philly_ambient/$month";
$nearpath = "/home/mailman/archives/private/philly_ambient";



# Begin Mailman edits

$string = <<EOT;
#!/bin/sh

cd $path

rpl -qi 'href="00' 'href="$url/00' *.html
rpl -qi 'href="subject.html' 'href="$url/subject.html' *.html
rpl -qi 'href="author.html' 'href="$url/author.html' *.html
rpl -qi 'href="date.html' 'href="$url/date.html' *.html
rpl -qi 'href="thread.html' 'href="$url/thread.html' *.html


# Archived message replacements

rpl -i -q 'HREF="$url/mailto:' 'HREF="mailto:' *.html
rpl -q '<B>philly_ambient\@phobos.serve.com' '<B>.   .  . .. .  .   .' *.html
rpl -q '<I>philly_ambient\@phobos.serve.com' '<I>' *.html
rpl -q '">philly_ambient\@phobos.serve.com' '">' *.html

rpl -q '<I>philly_ambient\@simpletone.com' '<I>' *.html
rpl -q 'B>philly_ambient\@simpletone.com' 'B>.   .  . .. .  .   .' *.html
rpl -q '">philly_ambient\@simpletone.com' '">' *.html

EOT

$file1 = "/usr/local/bin/editphillyambient";
open (PRG, ">$file1");
print PRG ($string);
close PRG;
chmod 0755, $file1;
system ("$file1");




system ("touch $nearpath/latest.htm");

@files = `ls $path`;

#pop @files;
pop @files;
pop @files;
pop @files;
pop @files;
pop @files;

$file = pop(@files);

print $path/$file;

open (IN, "$path/$file");
open (OUT, ">$nearpath/latest.htm");

while ($line = <IN>) {

    $Text::Wrap::columns = 90;
    $pre1 = "";
    $pre2 = "";
    $line =~ s/<hr>//gi;
    $line =~ s/\[Philly_ambient\]//gi;
    $line =~ s/<\/A><BR>/<\/A>/gi;
    print OUT wrap($pre1, $pre2, $line);

}

close(IN);
close(OUT); 


