"My company has a historical division between the IT Department and the Web Department," writes D. S. Black. "The IT Department does all the normal 'IT' stuff, while the Web folks mostly do non-technical like designing websites, creating simple databases, and configuring web servers. As a result, we've had a few web administrators who haven't quite been All There when it comes to things like reusable libraries, sensible documentation, and database design."

"One server I came across had at least a dozen different form-mail scripts. The earlier ones were written in Perl, but as the years passed, the secret of sending E-mail from Perl was lost. A few of the Perl scripts called Blat (a Win32 command line E-Mail utility), but eventually, even that knowledge was lost.

"This left the web developers with only a single technique for sending an email based on an HTML from: an ASP page called "formmail.asp". However, since they still needed to send mail from Perl scripts, one of the clever web developers managed to take a form submission in a Perl script and POST it to formmail.asp using LWP, a Perl lib that can that can be used as an HTTP client. This method was used time and time again, leaving several of the Perl scripts to accept a form submission, initiate another HTTP connection from the server, and then submit the same form values to the ASP page.

"Of course, all this paled in comparison to the One Script that I found. It was one of the countless things that broke when we moved to a new Web server.

"On the surface, the One Script looked like any other that is seen through many of our Web sites: it doesn't use strict or warnings; it doesn't use the standard CGI module to do any work, instead decoding the query string manually; it hard-codes paths and values that will break easily; and it even has a comment from someone questioning why it's still being used.

"But unlike other Perl scripts, the One Script does things... differently.

print "Content-Type: text/html



"; # parse form 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; $FORM{$name} = $value; } # Define variables ########################################### $quiz_name = $FORM{'quiz_name'}; $my_score = $FORM{'my_score'}; $email = $FORM{'stu_email'}; $name = $FORM{'stu_name'}; $prof_email = $FORM{'prof_email'}; # $email_message = "$answ"; $message = 'mailer_d_alt.asp'; $answ = $FORM{'answ'}; $new_answ = $answ; $new_answ =~ s/"//g; $new_answ =~ s/

/\" \& vbcrlf \& \"/g; $new_answ =~ s/\r//g; $final_answ = "(\"$new_answ\")"; $final_page = $FORM{'final_page'}; $final_page =~ s/\\/\//g; $final_page =~ s/e://g; $final_page =~ s/\/Inetpub\/wwwroot/http:\/\/www.thecompany.com/ig; # $final_page =~ s/\/inetpub\/wwwroot/http:\/\/www.thecompany.com/g; $page = $final_page; # Print asp page that will process and mail quiz response # NOTE: this seems a little ridiculous to me. why are we even using this # script if all it's going to do is just create another script? # -- XXXX XXXX, 2003-10-17 open(FILE,">$message") || print "<B>Error:</B> Could not create temporary file."; print FILE "<\%

"; print FILE "email = (\"$email\")

"; print FILE "Dim objCDO

"; print FILE "Dim strFromName

"; print FILE "Dim strFromEmail, strToEmail

"; print FILE "Dim strSubject, strBody

"; print FILE "strSubject = \"Results for $quiz_name\"

"; print FILE "strFromName = ((\"$name\"))

"; print FILE "strPage = ((\"$page\"))

"; print FILE "strFromEmail = ((\"mailer\@thecompany\"))

"; print FILE "strToEmail = \"$email\"

"; print FILE "strCcEmail = \"$prof_email\"

"; print FILE "strBody=$final_answ

"; print FILE "Set objCDO = Server.CreateObject(\"CDO.Message\")

"; print FILE "objCDO.From = strFromName \& \" <\" \& strFromEmail \& \">\"

"; print FILE "objCDO.To = strToEmail

"; print FILE "objCDO.Cc = strCcEmail

"; print FILE "objCDO.Subject = strSubject

"; print FILE "objCDO.Textbody = vbcrlf & strbody & vbcrlf

"; print FILE "objCDO.Send

"; print FILE "Set objCDO = Nothing

"; print FILE "response.redirect strPage

"; print FILE "response.end

"; print FILE "\%>"; close FILE; # mail.BodyFormat = MailFormat.Html

print "<HTML><HEAD><META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;"; print "URL=http://www.thecompany.com/scripts/mailer_d_alt.asp\">"; print "<TITLE></TITLE></HEAD><BODY></BODY></HTML>";

For those not acclimated with Perl, the One Script works by parsing the querystring, generating an ASP page (mailer_d_alt.asp) which sends out a basic confirmation email, and then redirects the user to the just-generated page.