Demon Mailform Unmangler


Thanks to Demon, we have a web page to call our own. They have even provided a nice CGI script to send mail to webmaster@<nodename>.demon.co.uk.

Example Form

Here is an example of the type of form that can be produced.
To: amb@gedanken.demon.co.uk

Subject: Example of the Demon mailform usage

From:

There are check boxes Checkbox 1 / Checkbox 2 / Checkbox 3 ,

radio buttons Radio 1 / Radio 2 / Radio 3 / Radio 4 ,

and text fields

This is generated by the trivially simple piece of HTML.
<form action="/cgi-bin/mailform" method=get>

<input name="format" type="hidden" value="Example">

<input name="to" type="hidden" value="amb@gedanken.demon.co.uk">
To: amb@gedanken.demon.co.uk
<p>
<input name="subject" type="hidden" value="Example of the Demon mailform usage">
Subject: Example of the Demon mailform usage
<p>
From:<input name="from" type="text" size=40>
<p>
There are check boxes
 <input name="check1" type="checkbox"         value="Y"> Checkbox 1
/<input name="check2" type="checkbox"         value="Y"> Checkbox 2
/<input name="check3" type="checkbox" checked value="Y"> Checkbox 3
,<p>
radio buttons
 <input name="radio" type="radio" checked value="1"> Radio 1
/<input name="radio" type="radio"         value="2"> Radio 2
/<input name="radio" type="radio"         value="3"> Radio 3
/<input name="radio" type="radio"         value="4"> Radio 4
<p>
,and text fields
<input name="text" type="text" size=60 maxlength=240 value="">
</p>
<input type="submit" value="Really send the Example"><input type="reset" value="Reset">

</form>

Format Of Output

The output that this form produces looks like.
Date: Tue, 6 Aug 1996 06:22:57 GMT
Message-Id: >199608060622.GAA25106@homepages.demon.co.uk>
From: internet@demon.net
Subject: web page form mail
To: webmaster@gedanken.demon.co.uk

This data is mailed from your web page http://www.gedanken.demon.co.uk/demon/webmaster.html
The host that sent this request was www-cache.demon.co.uk [158.152.1.54]
(although if a proxy was used, you will get the address of the proxy instead)
The user's browser reported itself to be
	Mozilla/1.12 (X11; I; Linux 1.2.13 i486)  via proxy gateway  CERN-HTTPD/3.0 libwww/2.17

----- BEGIN FORM -----
format	Example
to	amb@gedanken.demon.co.uk
subject	Example of the Demon mailform usage
from	foo@bar.com
check1	Y
check3	Y
radio	2
text	some text
----- END FORM -----
Wouldn't you prefer it if this looked like this instead?
Date: Tue, 6 Aug 1996 06:22:57 GMT
Subject: Example of the Demon mailform usage
From: foo@bar.com
To: amb@gedanken.demon.co.uk
X-Host: www-cache.demon.co.uk [158.152.1.54]
X-Browser: Mozilla/1.12 (X11; I; Linux 1.2.13 i486)  via proxy gateway  CERN-HTTPD/3.0 libwww/2.17
X-Webpage: http://www.gedanken.demon.co.uk/demon/webmaster.html

I really liked your example of an unmangled Demon mailform message.
I tried it out and selected the checkboxes "checkbox 1" "checkbox 3",
from the selection of radio buttons I selected "radio 2",
and I made the comment
"some text"
in the space at the bottom.
The fields to, from and subject fields from the form have been used as the unmangled mail header. The other fields in the form have been substituted in a predefined mail body, whose format depends on the format field.

How Did He Do That?

It was simple really, all it takes is an alias, a shell script and a number of perl scripts.

The Alias

In /etc/aliases, you need to add the alias for webmaster.
postmaster:	root
webmaster:	|/home/demon/www/webmaster
This will redirect all of the mail for webmaster to a program, in this case the shell script.

The Shell Script

The shell script webmaster is saved as /home/demon/www/webmaster is the shell script. What this does is to make a copy of the mail message as it comes in and pass it on to the first perl script. If the perl script accepts it as coming from a mailform CGI then the shell script is finished. If not then the copy of the mail message is sent to postmaster instead, this ensures that no mail is lost.

The Perl Scripts

The perl script webmaster.pl is saved as the file /home/demon/www/webmaster.pl. This perl script needs to make the decision as to whether the message is from a form or not. If it is from a form then it needs to format the information in the 'form' part of the mail message. This is performed by a second perl script, the name of which depends on the format field in the form. In this case the second perl script Example.pl is saved as /home/demon/www/Example.pl. This takes the information in the form fields and formats it to make the body of the message. This is put together with the header information from the to, from and subject fields.

Disclaimer: This worked for me, I can't guarantee it will for other Demon homepage users.