home *** CD-ROM | disk | FTP | other *** search
- /* HTML Fax Utility. Should be run as a cgi file under
- Mosaic. Takes the variable string supplied from the
- Mosaic "Form" submittal and parses it into an E-mail
- address ...The order that the variables appear in the
- html form are important. They must appear in the form
- in the same order that they are listed in the defines
- below... ie AT..FROM. I admit that this is not the best
- way to do it and will fix it at some point. This will
- produce an e-mail message of the form:
-
- /FN=995-4122/AT=Troy_Downing/O=NYU/@text-fax.nyu.edu
-
- text-fax.nyu will parse the "to" line and create a fax
- cover page and attempt to fax it to the number listed
- after /FN= Currently all spaces are converted to under-
- scores in the address but not in the body.
-
- the fax is mailed from nobody@found.cs.nyu.edu and this
- will appear on the header as the sender. So, It's important
- to include the FROM string so that the recipiant will
- know who it came from...
-
- */
-
-
- #include <stdio.h>
- #include <stdlib.h>
-
- #define MAILER "/usr/ucb/mail"
- #define LOGFILE "/shaggy.a/downing/pub/fax.log"
- #define LF 10
- #define MAX_ENT 1000 /* max number of variables
- that can be sent form form*/
- #define FAX "@text-fax.nyu.edu" /* could be ps-fax.nyu.edu
- if sending postscript files */
-
- /* header index. used to index the struct array containing the
- variables passed from mosaic */
-
- #define AT 0
- #define SUBJECT 1
- #define FN 2
- #define O 3
- #define OU 4
- #define BODY 5
- #define FROM 6
-
- typedef struct {
- char *name;
- char *val;
- } entry;
-
-
- char *makeword(char *line, char stop);
- char *fmakeword(FILE *f, char stop, int *len);
- char x2c(char *what);
- void unescape_url(char *url);
- void plustospace(char *str);
- void plusto_(char *str);
-
- void main(int argc, char *argv[])
- {
-
- entry entries[MAX_ENT];
- int cont_len,index,marker;
- char address[256];
- FILE *mdata, *log;
-
- index=marker=0;
-
- cont_len = atoi(getenv("CONTENT_LENGTH"));
-
- for(index=0;cont_len&& (!feof(stdin));index++)
- {
- marker=index;
- entries[index].val = fmakeword(stdin,'&',&cont_len);
-
- if ( index == BODY)
- plustospace(entries[index].val);
- else
- plusto_(entries[index].val);
-
- unescape_url(entries[index].val);
- entries[index].name = makeword(entries[index].val,'=');
- }
-
- printf("Content-type: text/html%c%c",LF,LF);
-
- /* put together e-mail address */
-
- sprintf(address, "%s -s %s /FN=%s/AT=%s/O=%s/OU=%s/%s",
- MAILER, entries[SUBJECT].val, entries[FN].val,
- entries[AT].val, entries[O].val, entries[OU].val,FAX);
-
- if (!(mdata=popen(address,"w"))){
- printf("<h1>Unable to open mail pipe</h1>%c",LF);
- exit(-1); }
-
- fprintf(mdata,"%s %c",entries[BODY].val,LF);
- fprintf(mdata,"%c%cMessage Sender: %s",LF,LF,entries[FROM].val);
-
- printf("<h1>Mail sent!</h1> %c",LF);
- printf("content follows:<p><hr>%c",LF);
-
- log=fopen(LOGFILE, "a");
- fprintf(log,"----------\n");
-
- for(index=0; index <= marker; index++)
- {
- printf("%s: %s<p>",entries[index].name,
- entries[index].val);
- fprintf(log,"%s: %s\n",entries[index].name,
- entries[index].val);
- }
-
- fprintf(log,"----------end--\n");
-
- pclose(mdata);
- fclose(log);
- exit(0);
-
- }
-
-