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

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