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   
Internet Message Format  |  1995-02-09  |  7KB

  1. From icon-group-sender Sat Feb  4 19:41:11 1995
  2. Received: by cheltenham.cs.arizona.edu; Sat, 4 Feb 1995 19:40:58 MST
  3. Date: Sat, 4 Feb 95 20:43:44 CST
  4. From: goer@mithra-orinst.uchicago.edu (Richard L. Goerwitz)
  5. Message-Id: <9502050243.AA08637@mithra-orinst.uchicago.edu>
  6. To: icon-group@cs.arizona.edu
  7. Subject: more Icon, CGI
  8. Errors-To: icon-group-errors@cs.arizona.edu
  9. Status: R
  10.  
  11. Another invitation to Icon users interested in the Web and CGI
  12. scripts....
  13.  
  14. Not all clients implement mailto, so if you want, say, for people
  15. reading an article you wrote to be able to mail you comments from
  16. a form, you need a form and a CGI script to do this.  Here are ex-
  17. amples of both.
  18.  
  19. Appended below, immediately after my signature, is a short HTML
  20. form.  After that is an Icon program that does the mailing.  It is
  21. simple, and probably could be improved in many ways.  I provide it
  22. here merely as an example.
  23.  
  24. Naturally, the mailing addresses and hard-coded system files will
  25. need to be changed.  Name the form anything you want.  Compile the
  26. Icon program and put it into the cgi-bin directory.  I recall when
  27. I first installed the executable running into problems with version
  28. 8 of Icon.  Version 9, though, worked fine.
  29.  
  30. Anyone wanting to take a look at how the form works can just jump
  31. to the end of one of the following documents.  I tend to put an
  32. HREF to the comments form at the end of docs I place online.
  33.  
  34.    http://oi.uchicago.edu:1080/pub/stuff/accents/accents.html
  35.    http://oi.uchicago.edu:1080/pub/papers/goerwitz/sbl94talk/sbl94talk.html
  36.  
  37. Richard Goerwitz
  38.  
  39.  
  40. =============================== cut here =========================
  41. <HTML>
  42.  
  43. <HEAD>
  44.   <TITLE>Feedback Form</TITLE>
  45. </HEAD>
  46.  
  47. <BODY>
  48.  
  49.   <H1>Feedback Form</H1>
  50.  
  51.   <P>This form offers a quick, easy way of forwarding comments back to me.
  52.     Just fill out the fields below, and then click on the "mail comments"
  53.     button near the end.
  54.   </P>
  55.  
  56.   <FORM METHOD="POST" ACTION="http://oi.uchicago.edu:1080/cgi-bin/forward_comments">
  57.   <P>E-mail: <INPUT NAME="sender"> Your name: <INPUT NAME="name"></P>
  58.   <P>Paper title:  <INPUT NAME="title" SIZE=50></P>
  59.   <P>Comments you would like to offer:</P>
  60.     <TEXTAREA NAME="comments" ROWS=8 COLS=60></TEXTAREA>
  61.   <P><INPUT TYPE="submit" VALUE="mail comments to goer@midway.uchicago.edu"></P>
  62.   </FORM>
  63.  
  64.   <P>If you prefer, send your comments to <A HREF=
  65.     "http://oi.uchicago.edu:1080/~goer/cvrlg.html">me</A> manually, using your
  66.     local system mailer
  67.   </P>
  68.  
  69.   <HR>
  70.   <ADDRESS>Richard L. Goerwitz, goer@midway.uchicago.edu</ADDRESS>
  71.  
  72. </BODY>
  73.  
  74. </HTML>
  75.  
  76. ================================ cut here ==========================
  77.  
  78. ############################################################################
  79. #
  80. #    File:     forward_comments.icn
  81. #
  82. #    Subject:  Program to forward comments sent via a fillout form
  83. #
  84. #    Author:   Richard L. Goerwitz
  85. #
  86. #    $Revision$
  87. #
  88. ############################################################################
  89.  
  90. $define MYADDRESS "goer@midway.uchicago.edu"
  91.  
  92. procedure main(a)
  93.  
  94.     local i, cl, n, name_tbl, f, sender, comments, nam, subj
  95.  
  96.     cl := integer(getenv("CONTENT_LENGTH"))
  97.     name_tbl := table()
  98.  
  99.     #
  100.     # output a minimal header, terminated by two newlines
  101.     #
  102.     write("Content-type: text/html\x0A\x0A")
  103.  
  104.     #
  105.     # check that the request is correctly formatted; output
  106.     # error message if it's not
  107.     #
  108.     getenv("REQUEST_METHOD") == "POST" | {
  109.         writes("<P>error:  METHOD must = \"POST\"</P>")
  110.         exit(1)
  111.     }
  112.     getenv("CONTENT_TYPE") == "application/x-www-form-urlencoded" | {
  113.         writes("<P>error:  this script is for decoding form results only</P>")
  114.         exit(1)
  115.     }
  116.  
  117.     #
  118.     # enter name=value lines as key/value pairs in name_tbl
  119.     #
  120.     while line := makeline(&input, "&", cl) do {
  121.     line := unescape_url(map(line, "+", " "))
  122.     line ? {
  123.         n := tab(find("="))
  124.         move(1)
  125.         if not (/name_tbl[n] := tab(0)) then {
  126.         writes("<P>error:  duplicate field name, ", n, "</P>")
  127.         exit(1)
  128.         }
  129.     }
  130.     }
  131.  
  132.     writes("<HTML><HEAD><TITLE>Feedback Submission Results</TITLE></HEAD>")
  133.     writes("<BODY>")
  134.     writes("<H1>Feedback submission results:</H1>")
  135.  
  136.     #
  137.     # Collect the mailing address of the sender & his or her comments
  138.     #
  139.     sender   := ("" ~== \name_tbl["sender"])    | {
  140.     writes("<P>error:  you forgot to give your e-mail address</P>")
  141.     exit(2)
  142.     }
  143.     comments := ("" ~== \name_tbl["comments"])    | {
  144.     writes("<P>error:  no comments found!</P>")
  145.     exit(2)
  146.     }
  147.     nam   := ("" ~== \name_tbl["name"])        | "(unknown)"
  148.     title := ("" ~== \name_tbl["title"])    | "(unspecified)"
  149.     subj  := "comments from " || nam || " (" || sender || ") regarding " || title
  150.  
  151.     #
  152.     # Send off comments using system mailer
  153.     #
  154.     f := open("Mail -s '"|| subj ||"' "|| MYADDRESS, "pw") | {
  155.     writes("<P>error:  mailer offline</P>")
  156.     exit(3)
  157.     }
  158.     write(f, comments)
  159.     close(f)
  160.  
  161.     #
  162.     # Report results to the comment-er
  163.     #
  164.     writes("<P>Your comments have been successfully forwarded.</P>")
  165.     writes("<P>Here is the text of what you sent:</P>")
  166.     writes("<PRE>", comments, "</PRE><HR>")
  167.     writes("<P>Thanks for your input,</P>")
  168.     writes("<P>Richard Goerwitz <ADDRESS>" || MYADDRESS || "</ADDRESS></P>")
  169.     writes("</BODY></HTML>")
  170.  
  171.     exit(0)
  172.  
  173. end
  174.  
  175.  
  176. #
  177. # concatenate series of non-ampersands into lines; stop
  178. # when you have read the number of characters in cl (arg
  179. # 3); stop_c is going to be "&"
  180. #
  181. procedure makeline(f, stop_c, cl)
  182.  
  183.     local line, c
  184.     static c_count
  185.     initial c_count := 0
  186.  
  187.     line := ""
  188.     while c := reads(f) do {
  189.     if (c_count +:= 1) > cl then
  190.         break
  191.         if c == stop_c then
  192.         break
  193.     line ||:= c
  194.     }
  195.     return "" ~== line
  196.  
  197. end
  198.  
  199.  
  200. #
  201. # turn &xx (where xx are hex digits) into an integer;
  202. # output the character with that internal integer value
  203. #
  204. procedure unescape_url(url)
  205.  
  206.     local new_url
  207.  
  208.     new_url := ""
  209.  
  210.     url ? {
  211.     while new_url ||:= tab(find("%")) & move(1) do
  212.         new_url ||:= char(hex(move(2))) | tab(0)
  213.     new_url ||:= tab(0)
  214.     }
  215.  
  216.     return new_url
  217.  
  218. end
  219.  
  220.  
  221. #
  222. # Bob Alexander's hex->integer code (overkill here)
  223. #
  224. procedure hex(s)
  225.  
  226.    local a,c
  227.  
  228.    a := 0
  229.    every c := !map(s) do
  230.        a := ior(find(c,"0123456789abcdef") - 1, ishift(a,4)) | fail
  231.    return a
  232.  
  233. end
  234. #
  235. #
  236. procedure hexstring(i,n,lowercase)
  237.  
  238.    local s, hexchars, sign
  239.  
  240.    i := integer(i) | runerr(101, i)
  241.    sign := ""
  242.    if i = 0 then s := "0"
  243.    else {
  244.        if /n & i < 0 then {
  245.        sign := "-"
  246.        i := -i
  247.        }
  248.        hexchars := if \lowercase
  249.        then "0123456789abcdef"
  250.        else "0123456789ABCDEF"
  251.        s := ""
  252.        until i = (0 | -1) do {
  253.        s := hexchars[iand(i,15) + 1] || s
  254.        i := ishift(i,-4)
  255.        }
  256.    }
  257.    if \n > *s then s := right(s,n,if i >= 0 then "0" else hexchars[16])
  258.  
  259.    return sign || s
  260.  
  261. end
  262.  
  263.