Annotation of researchv10no/cmd/netnews/src/recmail.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * recmail: read a mail message on stdin, grab all addresses in To and Cc
                      3:  * lines, and pass the full message to all addressees.  This is useful to
                      4:  * send the output of a recently edited mail message (with headers edited too).
                      5:  * It is similar to sendmail -t, but only assumes /bin/mail.
                      6:  */
                      7: static char *sccsid = "@(#)recmail.c   1.2     3/30/83";
                      8: 
                      9: #include <stdio.h>
                     10: #include <ctype.h>
                     11: 
                     12: #define MAXRECIPS 100
                     13: char *recips[MAXRECIPS];
                     14: int nrecips = 0;
                     15: 
                     16: main(argc, argv)
                     17: char **argv;
                     18: {
                     19:        FILE *fd;
                     20:        char *tmpf;
                     21:        char linebuf[1024];
                     22:        char *mailer = "mail";  /* /bin/mail */
                     23:        int i, pid, wpid;
                     24:        int exstat;
                     25:        char *mypath;
                     26:        char *mktemp(), *getenv();
                     27: 
                     28:        tmpf = mktemp("/tmp/rmXXXXXX");
                     29:        fd = fopen(tmpf, "w");
                     30: 
                     31:        while (fgets(linebuf, sizeof linebuf, stdin) != NULL) {
                     32:                fputs(linebuf, fd);
                     33:                if (strncmp(linebuf, "To: ", 4) == 0 ||
                     34:                    strncmp(linebuf, "to: ", 4) == 0 ||
                     35:                    strncmp(linebuf, "TO: ", 4) == 0 ||
                     36:                    strncmp(linebuf, "Cc: ", 4) == 0 ||
                     37:                    strncmp(linebuf, "cc: ", 4) == 0 ||
                     38:                    strncmp(linebuf, "CC: ", 4) == 0)
                     39:                        addrecips(linebuf+4);
                     40:        }
                     41:        fclose(fd);
                     42: 
                     43:        /*
                     44:         * Force the path to only consider /bin and /usr/bin, since
                     45:         * that's the version of mail we want (not /usr/ucb/mail)
                     46:         */
                     47:        mypath = getenv("PATH");
                     48:        if (mypath)
                     49:                strcpy(mypath, "/bin:/usr/bin");
                     50: 
                     51:        /*
                     52:         * We send the copies out separately, because of a bug in
                     53:         * USG's /bin/mail which will generate ANOTHER To: line,
                     54:         * even though we already have one, if there are at least
                     55:         * two recipients.
                     56:         */
                     57:        for (i=0; i<nrecips; i++) {
                     58:                /*
                     59:                 * mail recips[i] < tmpf
                     60:                 */
                     61:                while ((pid = fork()) == -1) {
                     62:                        fprintf(stderr, "fork failed, waiting...\r\n");
                     63:                        sleep(60);
                     64:                }
                     65:                if (pid == 0) {
                     66:                        close(0);
                     67:                        open(tmpf, 0);
                     68:                        execlp("mail", "mail", recips[i], 0);
                     69:                        perror("mail");
                     70:                        exit(1);
                     71:                }
                     72:                while ((wpid = wait(&exstat)) >= 0 && wpid != pid)
                     73:                        ;
                     74:        }
                     75: }
                     76: 
                     77: #define isok(c) (isprint(c) && (c) != ' ' && c != ',')
                     78: addrecips(line)
                     79: char *line;
                     80: {
                     81:        char *front, *back, *tail;
                     82:        char *malloc();
                     83: 
                     84:        tail = line + strlen(line);
                     85:        for (front=line; front < tail; ) {
                     86:                while (!isok(*front) && front < tail)
                     87:                        front++;
                     88:                for (back=front; isok(*back); back++)
                     89:                        ;
                     90:                *back=0;
                     91:                recips[nrecips] = malloc(strlen(front) + 1);
                     92:                strcpy(recips[nrecips], front);
                     93:                nrecips++;
                     94:                front = back+1;
                     95:        }
                     96: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.