home *** CD-ROM | disk | FTP | other *** search
- /* This works with a specific fax-modem terminal that
- the author runs locally. The fax modem takes e-mail as
- its input. This may need to be modified to work on your
- system.
-
- HTML Fax Utility. Should be run as a cgi file under
- HTTPD. Takes the variable string supplied from the
- HTML "Form" submittal and parses it into an e-mail
- address.... The order that the variables appear in the
- html form is important. They must appear in the form
- in the same order that they are listed in the defines
- below, that is, AT..FROM. (Not the best approach for the
- job; it'll get fixed 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
- underscores in the address but not in the body.
-
- The fax is mailed from nobody@yourserver.com and this
- will appear on the header as the sender. So, Its
- important to include the FROM string so that the
- recipient will know who it came from....
-
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include "util.h"
- #define MAILER "/usr/ucb/mail"
- #define LOGFILE "/usr/logs/fax.log"
- #define LF 10
- #define MAX_ENT 1000 /* max number of variables
- that can be sent from form*/
- #define FAX "@text-fax.myserver.com"
-
- /* 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;
-
- 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);
-
-
- }
-