|
For all your Islamic shopping needs
#!/usr/local/bin/perl
# ========================================================================
# Copyright (c) 1997 Infohiway by Ken Covell
# Infohiway mailgram program
# mailer.cgi
#
# Sends an email based on the input variables and then transfers the page.
#
# Input instructions:
# - "transfer" input variable stores the URL where the script sends them
# - "email" input variable stores the address of the sender
# - "recipient" input variable stores the receiver's email address
# - "sub" input variable stores the subject of the email
# - *all* input is dumped into the body of the message
#
# ========================================================================
MAIN:
{
# $ENV{'REQUEST_METHOD'} = 'GET'; #remove comment tag to allow simulation
# $ENV{'QUERY_STRING'} =
'email=ttt%40junk%2ecom&name=Joe+Blow&sub=subject&body=test+message'; #sim
$mailActive = 1; # comment out to simulate
$mailProg = "/usr/lib/sendmail -t -n -oi";
&getInput();
$| = 1;
open(STDOUT, ">test.htm") if !$mailActive; # for simulation purposes
unless ($input{'transfer'}) {
$input{'transfer'} = 'http://www.infohiway.com/javascript/indexf.htm';
}
unless ($input{'recipient'}) {
$input{'recipient'} = "nobody\@nowhere.com";
}
&sendMail;
exit;
}
sub sendMail
{
$input{'email'} =~ s/ .*//;
my $errMsg = '';
unless ($input{'email'} =~ /([\w-.]+\@[\w-.]+)/) {
$errMsg .= "Invalid email address. Try again.
";
}
if ($errMsg) {
&htmlForm($errMsg);
} else {
if ($mailActive) {
open (MAIL, "|$mailProg");
&writeMail;
close(MAIL);
if ($input{'transfer'}) {
print STDOUT "Location: $input{'transfer'}\n\n";
} else {
print STDOUT "Content-type: text/html\n\n";
print STDOUT '
';
}
} else {
&simMail; #simulate mail
}
}
}
sub writeMail
{
print MAIL <
Infohiway Mailer
$errMsg
EOT
}
sub getInput
{
my($allInput, @allPairs, $pair, $label, $value);
#parse the variable buffer both get and post
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$allInput = $ENV{'QUERY_STRING'};
} else {
read(STDIN,$allInput,$ENV{'CONTENT_LENGTH'});
}
@allPairs = split(/&/,$allInput);
while (@allPairs) {
$pair = shift @allPairs;
($label, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$body .= "$label=$value\n";
if ($input{$label}) {
$input{$label} .= "\|$value";
} else {
$input{$label} = $value;
}
}
}
sub simMail
{
print STDOUT <
Mail message would be sent as:
To: $input{'recipient'}
From: $input{'email'}
Subject: $input{'sub'}
$body
Transfer to URL:
$input{'transfer'}
|
|