#!/usr/bin/perl -w

use strict;

my $archive = "/home/www/html/ccp/archive.txt";

print "Content-type: text/html\n\n";

print "<title>The CVS Continuity Project Mail Archive</title>\n\n";
print "<html>\n";
print "<body bgcolor=ffffff fgcolor=000000>\n";
print "\n";
print "<p>\n";
print "\n";

print "<center>\n";
print "<h1><a href=\"index.html\">CCP</a> Mailing List Archive </h1>\n";
print "</center>\n";

print "\n<p>\n<hr>\n<p>\n";

print "<ol>\n";

open (ARCHIVE, "<$archive") or die ("unable to open $archive ($!)\n");

my $date = "";
my $sender = "";
my $subject = "";
my $count = 0;
while (<ARCHIVE>)
{
  chomp;

  if (/^From [^\s]+\s+([a-zA-Z]{3} [a-zA-Z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [0-9]{4})/) {
    $date = $1;
  }

  if (/^From: (.*)/) {
    $sender = $1;
  }

  if (/^Subject: (.*)/) {
    $subject = $1;
  }
      
  if ($date and $sender and $subject)
  {
    $count++;
    print "<li>Subject: <a href=\"find-msg.cgi?num-to-find=${count}\">"
        . "${subject}</a>"
        . "\n<br>\n($sender, $date)</li>\n<p>\n";
    $date = "";
    $sender = "";
    $subject = "";
  }
}

close (ARCHIVE);

print "\n";
print "</ol>\n";
print "\n";
print "</body>\n";
print "</html>\n";
