home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
contrib
/
webmail.txt
< prev
Wrap
Internet Message Format
|
1995-02-09
|
7KB
From icon-group-sender Sat Feb 4 19:41:11 1995
Received: by cheltenham.cs.arizona.edu; Sat, 4 Feb 1995 19:40:58 MST
Date: Sat, 4 Feb 95 20:43:44 CST
From: goer@mithra-orinst.uchicago.edu (Richard L. Goerwitz)
Message-Id: <9502050243.AA08637@mithra-orinst.uchicago.edu>
To: icon-group@cs.arizona.edu
Subject: more Icon, CGI
Errors-To: icon-group-errors@cs.arizona.edu
Status: R
Another invitation to Icon users interested in the Web and CGI
scripts....
Not all clients implement mailto, so if you want, say, for people
reading an article you wrote to be able to mail you comments from
a form, you need a form and a CGI script to do this. Here are ex-
amples of both.
Appended below, immediately after my signature, is a short HTML
form. After that is an Icon program that does the mailing. It is
simple, and probably could be improved in many ways. I provide it
here merely as an example.
Naturally, the mailing addresses and hard-coded system files will
need to be changed. Name the form anything you want. Compile the
Icon program and put it into the cgi-bin directory. I recall when
I first installed the executable running into problems with version
8 of Icon. Version 9, though, worked fine.
Anyone wanting to take a look at how the form works can just jump
to the end of one of the following documents. I tend to put an
HREF to the comments form at the end of docs I place online.
http://oi.uchicago.edu:1080/pub/stuff/accents/accents.html
http://oi.uchicago.edu:1080/pub/papers/goerwitz/sbl94talk/sbl94talk.html
Richard Goerwitz
=============================== cut here =========================
<HTML>
<HEAD>
<TITLE>Feedback Form</TITLE>
</HEAD>
<BODY>
<H1>Feedback Form</H1>
<P>This form offers a quick, easy way of forwarding comments back to me.
Just fill out the fields below, and then click on the "mail comments"
button near the end.
</P>
<FORM METHOD="POST" ACTION="http://oi.uchicago.edu:1080/cgi-bin/forward_comments">
<P>E-mail: <INPUT NAME="sender"> Your name: <INPUT NAME="name"></P>
<P>Paper title: <INPUT NAME="title" SIZE=50></P>
<P>Comments you would like to offer:</P>
<TEXTAREA NAME="comments" ROWS=8 COLS=60></TEXTAREA>
<P><INPUT TYPE="submit" VALUE="mail comments to goer@midway.uchicago.edu"></P>
</FORM>
<P>If you prefer, send your comments to <A HREF=
"http://oi.uchicago.edu:1080/~goer/cvrlg.html">me</A> manually, using your
local system mailer
</P>
<HR>
<ADDRESS>Richard L. Goerwitz, goer@midway.uchicago.edu</ADDRESS>
</BODY>
</HTML>
================================ cut here ==========================
############################################################################
#
# File: forward_comments.icn
#
# Subject: Program to forward comments sent via a fillout form
#
# Author: Richard L. Goerwitz
#
# $Revision$
#
############################################################################
$define MYADDRESS "goer@midway.uchicago.edu"
procedure main(a)
local i, cl, n, name_tbl, f, sender, comments, nam, subj
cl := integer(getenv("CONTENT_LENGTH"))
name_tbl := table()
#
# output a minimal header, terminated by two newlines
#
write("Content-type: text/html\x0A\x0A")
#
# check that the request is correctly formatted; output
# error message if it's not
#
getenv("REQUEST_METHOD") == "POST" | {
writes("<P>error: METHOD must = \"POST\"</P>")
exit(1)
}
getenv("CONTENT_TYPE") == "application/x-www-form-urlencoded" | {
writes("<P>error: this script is for decoding form results only</P>")
exit(1)
}
#
# enter name=value lines as key/value pairs in name_tbl
#
while line := makeline(&input, "&", cl) do {
line := unescape_url(map(line, "+", " "))
line ? {
n := tab(find("="))
move(1)
if not (/name_tbl[n] := tab(0)) then {
writes("<P>error: duplicate field name, ", n, "</P>")
exit(1)
}
}
}
writes("<HTML><HEAD><TITLE>Feedback Submission Results</TITLE></HEAD>")
writes("<BODY>")
writes("<H1>Feedback submission results:</H1>")
#
# Collect the mailing address of the sender & his or her comments
#
sender := ("" ~== \name_tbl["sender"]) | {
writes("<P>error: you forgot to give your e-mail address</P>")
exit(2)
}
comments := ("" ~== \name_tbl["comments"]) | {
writes("<P>error: no comments found!</P>")
exit(2)
}
nam := ("" ~== \name_tbl["name"]) | "(unknown)"
title := ("" ~== \name_tbl["title"]) | "(unspecified)"
subj := "comments from " || nam || " (" || sender || ") regarding " || title
#
# Send off comments using system mailer
#
f := open("Mail -s '"|| subj ||"' "|| MYADDRESS, "pw") | {
writes("<P>error: mailer offline</P>")
exit(3)
}
write(f, comments)
close(f)
#
# Report results to the comment-er
#
writes("<P>Your comments have been successfully forwarded.</P>")
writes("<P>Here is the text of what you sent:</P>")
writes("<PRE>", comments, "</PRE><HR>")
writes("<P>Thanks for your input,</P>")
writes("<P>Richard Goerwitz <ADDRESS>" || MYADDRESS || "</ADDRESS></P>")
writes("</BODY></HTML>")
exit(0)
end
#
# concatenate series of non-ampersands into lines; stop
# when you have read the number of characters in cl (arg
# 3); stop_c is going to be "&"
#
procedure makeline(f, stop_c, cl)
local line, c
static c_count
initial c_count := 0
line := ""
while c := reads(f) do {
if (c_count +:= 1) > cl then
break
if c == stop_c then
break
line ||:= c
}
return "" ~== line
end
#
# turn &xx (where xx are hex digits) into an integer;
# output the character with that internal integer value
#
procedure unescape_url(url)
local new_url
new_url := ""
url ? {
while new_url ||:= tab(find("%")) & move(1) do
new_url ||:= char(hex(move(2))) | tab(0)
new_url ||:= tab(0)
}
return new_url
end
#
# Bob Alexander's hex->integer code (overkill here)
#
procedure hex(s)
local a,c
a := 0
every c := !map(s) do
a := ior(find(c,"0123456789abcdef") - 1, ishift(a,4)) | fail
return a
end
#
#
procedure hexstring(i,n,lowercase)
local s, hexchars, sign
i := integer(i) | runerr(101, i)
sign := ""
if i = 0 then s := "0"
else {
if /n & i < 0 then {
sign := "-"
i := -i
}
hexchars := if \lowercase
then "0123456789abcdef"
else "0123456789ABCDEF"
s := ""
until i = (0 | -1) do {
s := hexchars[iand(i,15) + 1] || s
i := ishift(i,-4)
}
}
if \n > *s then s := right(s,n,if i >= 0 then "0" else hexchars[16])
return sign || s
end