home *** CD-ROM | disk | FTP | other *** search
/ The HTML Web Publisher's Construction Kit / HTMLWPCK.ISO / unix / cgi / c_src / fax.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-27  |  3.1 KB  |  124 lines

  1. /*     HTML Fax Utility. Should be run as a cgi file under
  2.     Mosaic. Takes the variable string supplied from the
  3.     Mosaic "Form" submittal and parses it into an E-mail
  4.     address ...The order that the variables appear in the
  5.     html form are important. They must appear in the form
  6.     in the same order that they are listed in the defines
  7.     below... ie AT..FROM. I admit that this is not the best
  8.     way to do it and will fix it at some point. This will
  9.     produce an e-mail message of the form:
  10.  
  11.     /FN=995-4122/AT=Troy_Downing/O=NYU/@text-fax.nyu.edu
  12.  
  13.     text-fax.nyu will parse the "to" line and create a fax
  14.     cover page and attempt to fax it to the number listed
  15.     after /FN= Currently all spaces are converted to under-
  16.     scores in the address but not in the body.
  17.  
  18.     the fax is mailed from nobody@found.cs.nyu.edu and this
  19.     will appear on the header as the sender. So, It's important
  20.     to include the FROM string so that the recipiant will 
  21.     know who it came from...
  22.  
  23. */
  24.  
  25.  
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28.  
  29. #define MAILER     "/usr/ucb/mail"
  30. #define LOGFILE "/shaggy.a/downing/pub/fax.log"
  31. #define LF     10
  32. #define MAX_ENT 1000             /*  max number of variables 
  33.                         that can be sent form form*/
  34. #define FAX    "@text-fax.nyu.edu" /*     could be ps-fax.nyu.edu 
  35.                     if sending postscript files */
  36.  
  37. /* header index. used to index the struct array containing the
  38.    variables passed from mosaic */
  39.  
  40. #define AT      0
  41. #define SUBJECT 1
  42. #define FN    2
  43. #define O    3
  44. #define OU    4
  45. #define BODY    5
  46. #define FROM     6
  47.  
  48. typedef struct {
  49.         char *name;
  50.         char *val;
  51.         } entry;
  52.  
  53.  
  54. char *makeword(char *line, char stop);
  55. char *fmakeword(FILE *f, char stop, int *len);
  56. char x2c(char *what);
  57. void unescape_url(char *url);
  58. void plustospace(char *str);
  59. void plusto_(char *str);
  60.  
  61. void main(int argc, char *argv[])
  62. {
  63.  
  64.     entry entries[MAX_ENT];
  65.     int cont_len,index,marker;
  66.     char address[256];
  67.     FILE *mdata, *log;
  68.  
  69.     index=marker=0;
  70.  
  71.     cont_len = atoi(getenv("CONTENT_LENGTH")); 
  72.  
  73.     for(index=0;cont_len&& (!feof(stdin));index++) 
  74.     {
  75.         marker=index;
  76.         entries[index].val = fmakeword(stdin,'&',&cont_len);
  77.  
  78.     if ( index == BODY)
  79.             plustospace(entries[index].val);
  80.     else
  81.         plusto_(entries[index].val);
  82.  
  83.         unescape_url(entries[index].val);
  84.         entries[index].name = makeword(entries[index].val,'=');
  85.     }
  86.  
  87.     printf("Content-type: text/html%c%c",LF,LF);
  88.  
  89.     /* put together e-mail address */
  90.  
  91.     sprintf(address, "%s -s %s /FN=%s/AT=%s/O=%s/OU=%s/%s", 
  92.          MAILER, entries[SUBJECT].val, entries[FN].val, 
  93.         entries[AT].val, entries[O].val, entries[OU].val,FAX);
  94.  
  95.     if (!(mdata=popen(address,"w"))){
  96.         printf("<h1>Unable to open mail pipe</h1>%c",LF);
  97.         exit(-1); }
  98.  
  99.     fprintf(mdata,"%s %c",entries[BODY].val,LF);
  100.     fprintf(mdata,"%c%cMessage Sender: %s",LF,LF,entries[FROM].val);
  101.  
  102.     printf("<h1>Mail sent!</h1> %c",LF);
  103.     printf("content follows:<p><hr>%c",LF);
  104.  
  105.     log=fopen(LOGFILE, "a");
  106.     fprintf(log,"----------\n");
  107.  
  108.     for(index=0; index <= marker; index++)
  109.     {
  110.         printf("%s:  %s<p>",entries[index].name,
  111.                entries[index].val);
  112.         fprintf(log,"%s:  %s\n",entries[index].name,
  113.                entries[index].val);
  114.     }
  115.  
  116.     fprintf(log,"----------end--\n");
  117.  
  118.     pclose(mdata);
  119.     fclose(log);
  120.     exit(0);
  121.  
  122. }
  123.  
  124.