#!/usr/bin/perl

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

print "<Head><Title>Thank you</Title></Head>";
print "<Body><H1>Thank you</H1>";

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);

    # Un-Webify plus signs and %-encoding
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;


    $FORM{$name} = $value;
}

&blank_response unless $FORM{'comments'};

print "Reply-to: $FORM{'username'} ($FORM{'comments'})";


open(F,">ttt");
print "Thhis is a test for $FORM{'username'} >> jj";
print F "Thhis is a test for $FORM{'username'}\n";
close(F);
print "Subject: WWW comments (Forms submission)\n\n";
print "$FORM{'username'} ($FORM{'realname'}) sent the following\n";
print "comment about The Tech's WWW server:\n\n";

print "Thank you for sending comments to <I>The Tech</I>!<P>";
print "Return to our <A HREF=\"/\">home page</A>, if you want.<P>";

sub blank_response
{
    print "Your comments appear to be blank, and thus were not sent ";
    print "to our webmasters.  Please re-enter your comments, or ";
    print "return to our <A HREF=\"/\">home page</A>, if you want.<P>";
    exit;
}
