Annotation of 43BSDTahoe/new/news/src/uurec.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * uurec - receive articles via /bin/mail.
                      3:  */
                      4: 
                      5: #ifdef SCCSID
                      6: static char    *SccsId = "@(#)uurec.c  2.11    3/21/87";
                      7: #endif /* SCCSID */
                      8: 
                      9: #include "defs.h"
                     10: 
                     11: #include <stdio.h>
                     12: #include <ctype.h>
                     13: 
                     14: /*
                     15:  * Process a news article which has been shipped via /bin/mail.
                     16:  */
                     17: 
                     18: #define FROM   01
                     19: #define NLIN   02
                     20: #define BLANK  03
                     21: #define OTHER  04
                     22: 
                     23: #define SKIPPING       010
                     24: #define READING                020
                     25: 
                     26: #define BFSZ 250
                     27: 
                     28: #define EOT    '\004'
                     29: 
                     30: #define A      01
                     31: #define B      02
                     32: 
                     33: #ifdef debug
                     34: # define RNEWS "cat"
                     35: #endif
                     36: extern char    *strcat(), *strcpy();
                     37: extern char    *frombreak();
                     38: extern FILE    *popen();
                     39: 
                     40: /* ARGSUSED */
                     41: main(argc, argv)
                     42: int argc;
                     43: char **argv;
                     44: {
                     45:        char buf[BFSZ], fbuf[BFSZ];
                     46:        char bfr[BFSZ], *pbfr = bfr;
                     47:        register char *p = NULL;
                     48:        register FILE *pipe = stdout;
                     49:        register int mode, frmflg, pathcnt, format;
                     50:        char *index();
                     51: 
                     52:        mode = SKIPPING;
                     53:        frmflg = FALSE;
                     54:        while (fgets(buf, BFSZ, stdin) != NULL) {
                     55: #ifdef debug
                     56:                printf("%o\t%s", mode|type(buf), buf);
                     57: #endif
                     58:                switch (mode | type(buf)) {
                     59: 
                     60:                case FROM | SKIPPING:
                     61:                        if (frmflg)
                     62:                                p = frombreak(p, buf);
                     63:                        else
                     64:                                p = fbuf;
                     65:                        frmflg = TRUE;
                     66:                        break;
                     67: 
                     68:                case FROM | READING:
                     69:                        if (!frmflg) {
                     70:                                frmflg = TRUE;
                     71:                                p = fbuf;
                     72:                                pclose(pipe);
                     73:                        }
                     74:                        p = frombreak(p, buf);
                     75:                        break;
                     76: 
                     77:                case NLIN | SKIPPING:
                     78:                        if ((isupper(buf[1]) && index(buf, ':')) || !strncmp(buf, "From ", 5))
                     79:                                format = B;
                     80:                        else
                     81:                                format = A;
                     82: #ifdef debug
                     83:                        printf("format = %d\n", format);
                     84: #endif
                     85:                        mode = READING;
                     86: 
                     87:                case NLIN | READING:
                     88:                        if (frmflg) {
                     89:                                frmflg = FALSE;
                     90:                                --p;
                     91:                                while (p >= fbuf && *--p != '!')
                     92:                                        ;
                     93:                                *++p = '\0';
                     94:                                pathcnt = 0;
                     95: #ifdef IHCC
                     96:                                sprintf(pbfr, "%s/%s", logdir(HOME), RNEWS);
                     97: #else
                     98:                                pbfr = RNEWS;
                     99: #endif
                    100:                                if ((pipe = popen(pbfr, "w")) == NULL) {
                    101:                                        perror("uurec: popen failed");
                    102:                                        exit(1);
                    103:                                }
                    104:                        }
                    105:                        if (format == A) {
                    106:                                if (++pathcnt == 3)
                    107:                                        fputs(fbuf, pipe);
                    108:                                fputs(buf+1, pipe);
                    109:                        } else {
                    110:                                if (!pathcnt && (!strncmp(buf+1, "From: ", 6) || !strncmp(buf+1, "From ", 5))) {
                    111:                                        pathcnt++;
                    112:                                        fprintf(pipe, "From: %s", fbuf);
                    113:                                        sscanf(buf, "%s %[^\n]", fbuf, fbuf);
                    114:                                        fprintf(pipe, "%s\n", fbuf);
                    115:                                } else
                    116:                                        fputs(buf+1, pipe);
                    117:                        }
                    118:                        break;
                    119: 
                    120:                case OTHER | SKIPPING:
                    121:                        break;
                    122: 
                    123:                case OTHER | READING:
                    124:                        pclose(pipe);
                    125:                        mode = SKIPPING;
                    126:                }
                    127:        }
                    128:        if (pipe && pipe != stdout)
                    129:                pclose(pipe);
                    130:        exit(0);
                    131: }
                    132: 
                    133: type(p)
                    134: register char *p;
                    135: {
                    136:        while (*p == ' ' || *p == '?')
                    137:                ++p;
                    138: 
                    139:        if (*p == 'N')
                    140:                return (NLIN);
                    141: 
                    142:        if (strncmp(p, ">From ", 6) == 0)
                    143:                return (FROM);
                    144: 
                    145:        if (strncmp(p, "From ", 5) == 0)
                    146:                return (FROM);
                    147: 
                    148:        return(OTHER);
                    149: }
                    150: 
                    151: /*
                    152:  * Get the system name out of a from line.
                    153:  */
                    154: char *
                    155: frombreak(buf, fbuf)
                    156: register char *buf, *fbuf;
                    157: {
                    158:        register char *p;
                    159: 
                    160:        /* break the line into tokens. */
                    161:        p = fbuf;
                    162:        while (*++p != '\0')
                    163:                switch (*p) {
                    164:                case '\n':
                    165:                case '\t':
                    166:                case ' ':
                    167:                        *p = '\0';
                    168:                        break;
                    169:                case EOT:
                    170:                        goto garbled;
                    171:                default:;
                    172:                }
                    173:        *++p = EOT;
                    174:        *++p = '\0';
                    175: 
                    176:        for (p=fbuf; *p != EOT  || p[1] != '\0'; p += strlen(p)+1) {
                    177:                if (strcmp(p, "forwarded") == 0)
                    178:                        return(buf);
                    179:                if (strcmp(p, "remote") == 0) {
                    180:                        p += strlen(p)+1;
                    181:                        if (strcmp(p, "from") == 0) {
                    182:                                p += strlen(p)+1;
                    183:                                strcpy(buf, p);
                    184:                                strcat(buf, "!");
                    185:                                return(buf+strlen(buf));
                    186:                        }
                    187:                }
                    188:        }
                    189:     garbled:
                    190:        strcat(buf, "???!");
                    191:        return(buf+4);
                    192: }

unix.superglobalmegacorp.com

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