Forms to E-Mail Using Tcl
by J.M. Ivler
Have It Your Way
How do you want the information returned to you? This has a great deal to do with how the information returned will be processed.
From a form, using this process, e-mail can look two ways. The first is that the message will contain value pairs matching the data with the variable that the data was in. For instance, consider the following HTML from the sample.
<li> Navigation at this site was easy.
1 <input name=m1 Type=radio value="1">
2 <input name=m1 Type=radio value="2">
3 <input name=m1 Type=radio value="3">
4 <input name=m1 Type=radio value="4">
5 <input name=m1 Type=radio value="5">
6 <input name=m1 Type=radio value="6">
7 <input name=m1 Type=radio value="7">
In answering this question, a radio button would be set which would set the variable m1 with the value 1 through 7, as selected by the user. In this case the answer, by itself, would be of little use in a mail message. By using value pairs, the e-mail message would contain (if the user selected the radio button 3):
m1 = 3
This would be useful if the data was to be processed into a database or table. For human-readable data, you would want the following HTML:
<li> Navigation at this site was easy.
1 <input name=m1 Type=radio value="Navigation was hard">
2 <input name=m1 Type=radio value="Navigation was difficult">
3 <input name=m1 Type=radio value="Navigation was uncomfortable">
4 <input name=m1 Type=radio value="Navigation was okay">
5 <input name=m1 Type=radio value="Navigation was fine">
6 <input name=m1 Type=radio value="Navigation was good">
7 <input name=m1 Type=radio value="Navigation was great">
Now when the user answered the form with a 3, the form data could be sent without the value pairs on. In this case the message sent via e-mail would look like:
Navigation was uncomfortable
This would be much harder to process into a database or table, but is much more informative for a person to read.
In order to support both possible methods of response, the code allows the person building the form to use a hidden variable, and keyword, sendvar. This variable is set with either a true or false value. The default is true. To set the default false, you would include the following HTML code:
<input type=hidden name=sendvar value="false">
Remember, that when sendvar is off (set false), all value pairs will not be printed. That means that the name, address, and other sections won't have "titles". Instead of:
name = J.M. Ivler
the email will just have the phrase
which you had better recognize as the "name" value. Consider the following:
<input name="mname"> Your Name<p>
<input name="fname"> Your Friend's Name<p>
mname = J.M. Ivler
fname = Steven Schwartz
In the first case we have sendvar set false, in the second we have it set true. As you can see, in a case like this, it might be better to leave the labels on, so it is clear who the friend is, versus who the respondent is.
Uncgi processes each form variable into a environment variable with the format WWW_<name>. The email.tcl processor loads all variables with a WWW_ prefix to the mail message. That includes WWW_mailto, WWW_msub and WWW_sendvar (the three keyword variables that email.tcl uses). The code can easily be modified to have these values removed from the mail; the regexp to do so has been included in this article. Having these displayed provides a useful debugging tool when trying to locate a problem.
Based on how the email.tcl has been installed, you can use this software as an anonymous remailer. If the software has been installed to allow for Internet addressing, then the users could be asked for the address that they wish to send the email to, and the software will send the email to any valid address. While this is not the purpose of the software, it could be used as such. The prior section clearly explained why you would want to ensure that the software is not being used in that way, but it can not be stressed enough that maintaining an anonymous mailer opens a Pandora's box of possible problems, and should be strongly avoided.
Installing the CGI (And Support Tools)
In order to use Tcl as a command language, the Tcl code must be compiled and installed on the system. While Tk is also available, and is highly recommended just for its own usefulness, it is not required in order to use Tcl.
Uncgi must also be installed on your system. As noted, there have been changes in the uncgi software, and the most current release is V1.5. Although the changes haven't been tested with email.tcl, the release notes indicate that the changes will not have an effect on email.tcl V2.0. If you wish to use V1.4 of uncgi, it will be kept available at the ftp.net-quest.com location. Unzip and untar the file, compile using a standard C compiler, and place the executable into the area you have defined as your cgi-bin on your Web server. Further details on the install can be found in the README file included in the distribution of uncgi. To install the email.tcl software at your site, simply FTP the software to your site and place it in the cgi-bin area of your webserver.
If you wish to pre-process the e-mail messages, you may want to obtain a copy of a software program called procmail. This public domain program will act as a filtering processor for your inbound e-mail. It is possible to set the software up in either a sitewide manner, or as a single user. Procmail can be obtained by FTP from gatekeeper.dec.com in /.b/usenet/comp.sources.misc/volume43 (the software is downloadable as 10 parts in compressed (.Z) format). It is highly recommended that you read all the documentation associated with procmail before installing it. Procmail is a very powerful filtering agent for e-mail, and as such should be fully understood before using it. Improper usage could cause e-mail to fail to be delivered as expected.