Ummmmm...... okay. Only if you want to. Only if you really, really, really want to. Only if there is something mentally wrong with you.
#! /usr/bin/perl
# print "Content-type: text/html\n\r\n\r";
# Read from the sandard input
read(STDIN,$query,$ENV{'CONTENT_LENGTH'});
$input = parseQs($query);
$message = parseEmailBody($query);
#$head="This is a multi-part message in MIME format.";
#$head=$head."Content-Type: text/plain; charset=us-ascii";
#$head=$head."Content-Transfer-Encoding: 7bit";
sendEmailWithoutAttachment(
'/usr/sbin/sendmail -t',
$input->{'recipient'},
$input->{'recipient'},
$input->{'e-mail_subject'},
$message );
print "LOCATION: " . $input->{'location'} . "\n\r\n\r";
#-------------------------
# SUBROUTINES FOLLOW
#-------------------------
sub parseQs{
my $query= shift;
my (%input,@elements,$element,$key,$value );
@elements=split(/&/,$query);
for $element(@elements) {
$element =~ tr/+/ /;
($key,$value)=split(/=/,$element);
$key =~ s/%([\dA-Fa-f]{2})/pack("C",hex($1))/ge;
$value =~ s/%([\dA-Fa-f]{2})/pack("C",hex($1))/ge;
if (defined $input{$key}) {
$input{$key} .= "\0$value";
} else {
$input{$key}=$value;
}
}
\%input;
}
sub parseEmailBody{
# Loop through the elements in $input and store in $msgBody
my $query= shift;
my (@elements,$element,$key,$value,$msgBody );
@elements=split(/&/,$query);
for $element(@elements) {
$element =~ tr/+/ /;
($key,$value)=split(/=/,$element);
$key =~ s/%([\dA-Fa-f]{2})/pack("C",hex($1))/ge;
$value =~ s/%([\dA-Fa-f]{2})/pack("C",hex($1))/ge;
$msgBody .= $key . " = " . $value . "\n\r";
}
return $msgBody;
}
sub sendEmailWithoutAttachment
{
# print "\n";
# Load in the parameters;
local($sendmail,$toAddress,$fromAddress,$subject,$message) = @_; # Load in the
parameters
# Send the email using sendmail;
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print( SENDMAIL "To: $toAddress\n");
print( SENDMAIL "From: $fromAddress\n");
print( SENDMAIL "Reply-To: $fromAddress\n");
print( SENDMAIL "Subject: $subject\n");
print( SENDMAIL "\n\n");
print( SENDMAIL $message);
close( SENDMAIL );
# print "\n";
}
|