#!/usr/bin/perl -w

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ s/\n/ /g; # replace newlines with spaces
    $FORM{$name} = $value;
}

if ($FORM{'Name'} eq "") {$FORM{'Name'} = 'Anonymous User';}
if ($FORM{'EMail'} eq "") {$FORM{'EMail'} = 'Anonymous User<bjabram\@johnny.sas.upenn.edu>';}

open(MAIL, "|/usr/sbin/sendmail -oi -t") or die "Can't open pipe to
$sendmail: $!\n";
print MAIL "To: bjabram\@johnny.sas.upenn.edu\n";
print MAIL "From: $FORM{'Name'}<$FORM{'EMail'}>\n"; 
print MAIL "Subject: Survey Comments\n\n";
print MAIL "$FORM{'Comments'}\n\n";
print MAIL "This originated from $FORM{'Name'}<$FORM{'EMail'}>";
close(MAIL) or die "Can't close pipe to $sendmail: $!\n";

print "Content-type: text/html\n\n";
print <<"EoF";
<html>
<head>
<title>Thank you for your time!</title>
</head>
<body>
<font face="Verdana" size="2">
<h2>Thank you for your time!</h2>
<p>Thank you for your comments. You have made the world a
better place.</p>
<p><center><font color="Red">NEW! </font><a
href="http://johnny.sas.upenn.edu/~bjabram/cgi-bin/fall00/survey/results.cgi">Current
Results of the Survey</a></center></p>
</face>
</body>
</html>
EoF
