Annotation of 40BSD/cmd/rmail.c, revision 1.1.1.1

1.1       root        1: static char *sccsid = "@(#)rmail.c     4.1 (Berkeley) 10/1/80";
                      2: /*
                      3:  * rmail: front end for mail to stack up those stupid >From ... remote from ...
                      4:  * lines and make a correct return address.  This works with the -f option
                      5:  * to /etc/delivermail so it won't work on systems without delivermail.
                      6:  * However, it ought to be easy to modify a standard /bin/mail to do the
                      7:  * same thing.
                      8:  *
                      9:  * NOTE: Rmail is SPECIFICALLY INTENDED for ERNIE COVAX because of its
                     10:  * physical position as a gateway between the uucp net and the arpanet.
                     11:  * By default, other sites will probably want /bin/rmail to be a link
                     12:  * to /bin/mail, as it was intended by BTL.  However, other than the
                     13:  * (somewhat annoying) loss of information about when the mail was
                     14:  * originally sent, rmail should work OK on other systems running uucp.
                     15:  * If you don't run uucp you don't even need any rmail.
                     16:  */
                     17: 
                     18: #include <stdio.h>
                     19: FILE *popen();
                     20: char *index();
                     21: 
                     22: #define MAILER "/etc/delivermail"
                     23: 
                     24: main(argc, argv)
                     25: char **argv;
                     26: {
                     27:        FILE *out;      /* output to delivermail */
                     28:        char lbuf[512]; /* one line of the message */
                     29:        char from[512]; /* accumulated path of sender */
                     30:        char ufrom[64]; /* user on remote system */
                     31:        char sys[64];   /* a system in path */
                     32:        char junk[512]; /* scratchpad */
                     33:        char cmd[512];
                     34:        char *to, *cp;
                     35: 
                     36:        to = argv[1];
                     37:        if (argc != 2) {
                     38:                fprintf(stderr, "Usage: rmail user\n");
                     39:                exit(1);
                     40:        }
                     41: 
                     42:        for (;;) {
                     43:                fgets(lbuf, sizeof lbuf, stdin);
                     44:                if (strncmp(lbuf, "From ", 5) && strncmp(lbuf, ">From ", 6))
                     45:                        break;
                     46:                /* sscanf(lbuf, "%s %s %s %s %s %s %s remote from %s", junk, ufrom, junk, junk, junk, junk, junk, sys); */
                     47:                sscanf(lbuf, "%s %s", junk, ufrom);
                     48:                cp = lbuf;
                     49:                for (;;) {
                     50:                        cp = index(cp+1, 'r');
                     51:                        if (cp == NULL)
                     52:                                cp = "remote from somewhere";
                     53: #ifdef DEBUG
                     54:                        printf("cp='%s'\n", cp);
                     55: #endif
                     56:                        if (strncmp(cp, "remote from ", 12)==0)
                     57:                                break;
                     58:                }
                     59:                sscanf(cp, "remote from %s", sys);
                     60:                strcat(from, sys);
                     61:                strcat(from, "!");
                     62: #ifdef DEBUG
                     63:                printf("ufrom='%s', sys='%s', from now '%s'\n", ufrom, sys, from);
                     64: #endif
                     65:        }
                     66:        strcat(from, ufrom);
                     67: 
                     68:        sprintf(cmd, "%s -r%s %s", MAILER, from, to);
                     69: #ifdef DEBUG
                     70:        printf("cmd='%s'\n", cmd);
                     71: #endif
                     72:        out = popen(cmd, "w");
                     73:        fputs(lbuf, out);
                     74:        while (fgets(lbuf, sizeof lbuf, stdin))
                     75:                fputs(lbuf, out);
                     76:        pclose(out);
                     77: }
                     78: 
                     79: /*
                     80:  * Return the ptr in sp at which the character c appears;
                     81:  * NULL if not found
                     82:  */
                     83: 
                     84: char *
                     85: index(sp, c)
                     86: register char *sp, c;
                     87: {
                     88:        do {
                     89:                if (*sp == c)
                     90:                        return(sp);
                     91:        } while (*sp++);
                     92:        return(NULL);
                     93: }

unix.superglobalmegacorp.com

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