#!/usr/bin/perl -WT

# $Id: ssend.pl,v 1.1.1.1 2003/10/04 16:01:42 karsten Exp $
#
# Since i've had some UCE-Issues at www.newbie-net.de with
# "formmail" from MCA i had to write my own cgi-mailer. Have
# fun with it and inform me if you experience ANY unexpected
# behavior. Features:
#
# - Only post-method is alowed!
# - Recipient is REALLY hardcoded!
# - Easy to read, easy to configure!
#
# Karsten Kruse (tecneeq@gmx.net)

use strict;

$mailer = "/usr/sbin/sendmail -t";
$valist = "";

# Get input and strip off all unwanted characters
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$temp = $buffer;
$temp =~ s/\+/ /g;
$temp =~ s/%([0-9|A-F]{2})/pack(C,hex($1))/eg;

# Store the matching name and value pairs
foreach (split(/&/,$temp))
{
	($NAM, $VAL) = split(/=/, $_);
	$DATA{$NAM} = $VAL;
	$valist .= "$NAM:$VAL\n";
}

# Grab necessary variables
$subject = $DATA{'subject'};
$usermail = $DATA{'usermail'};
$username = $DATA{'username'};

# Send the mail
open (MAIL, "|$mailer") || die "Can't open $mailprog!\n";
print MAIL "Subject: $subject\n";
print MAIL "From: $usermail ($username)\n";
print MAIL "To: karsten\@localhost\n";
print MAIL "\n";
print MAIL "$valist";
print MAIL "\n";
print MAIL "IP     : $ENV{'REMOTE_ADDR'}\n";
print MAIL "HOST   : $ENV{'REMOTE_HOST'}\n";
print MAIL "REFERER: $ENV{'HTTP_REFERER'}\n";
#close (MAIL);

# Redirect to a Page, whatever happens
print "Location: http://www.newbie-net.de/feedback_ok.html\n\n";
#print "Content-type:text/html\n\n";
#print "<HTML><BODY><TITLE>Thank you</TITLE>";
#print "<FONT SIZE=+2>Danke Schön :)</FONT>";
#print "</BODY></HTML>";

