|
|
1.1 ! root 1: /* ! 2: * uurec - receive articles via /bin/mail. ! 3: */ ! 4: ! 5: #ifdef SCCSID ! 6: static char *SccsId = "@(#)uurec.c 2.9 4/16/85"; ! 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/%s", logdir(HOME), ! 97: LIBDIR, "rnews"); ! 98: #else ! 99: pbfr = RNEWS; ! 100: #endif ! 101: if ((pipe = popen(pbfr, "w")) == NULL) { ! 102: perror("uurec: popen failed"); ! 103: exit(1); ! 104: } ! 105: } ! 106: if (format == A) { ! 107: if (++pathcnt == 3) ! 108: fputs(fbuf, pipe); ! 109: fputs(buf+1, pipe); ! 110: } else { ! 111: if (!pathcnt && (!strncmp(buf+1, "From: ", 6) || !strncmp(buf+1, "From ", 5))) { ! 112: pathcnt++; ! 113: fprintf(pipe, "From: %s", fbuf); ! 114: sscanf(buf, "%s %[^\n]", fbuf, fbuf); ! 115: fprintf(pipe, "%s\n", fbuf); ! 116: } else ! 117: fputs(buf+1, pipe); ! 118: } ! 119: break; ! 120: ! 121: case OTHER | SKIPPING: ! 122: break; ! 123: ! 124: case OTHER | READING: ! 125: pclose(pipe); ! 126: mode = SKIPPING; ! 127: } ! 128: } ! 129: if (pipe) ! 130: pclose(pipe); ! 131: exit(0); ! 132: } ! 133: ! 134: type(p) ! 135: register char *p; ! 136: { ! 137: while (*p == ' ' || *p == '?') ! 138: ++p; ! 139: ! 140: if (*p == 'N') ! 141: return (NLIN); ! 142: ! 143: if (strncmp(p, ">From ", 6) == 0) ! 144: return (FROM); ! 145: ! 146: if (strncmp(p, "From ", 5) == 0) ! 147: return (FROM); ! 148: ! 149: return(OTHER); ! 150: } ! 151: ! 152: /* ! 153: * Get the system name out of a from line. ! 154: */ ! 155: char * ! 156: frombreak(buf, fbuf) ! 157: register char *buf, *fbuf; ! 158: { ! 159: register char *p; ! 160: ! 161: /* break the line into tokens. */ ! 162: p = fbuf; ! 163: while (*++p != '\0') ! 164: switch (*p) { ! 165: case '\n': ! 166: case '\t': ! 167: case ' ': ! 168: *p = '\0'; ! 169: break; ! 170: case EOT: ! 171: goto garbled; ! 172: default:; ! 173: } ! 174: *++p = EOT; ! 175: *++p = '\0'; ! 176: ! 177: for (p=fbuf; *p != EOT || p[1] != '\0'; p += strlen(p)+1) { ! 178: if (strcmp(p, "forwarded") == 0) ! 179: return(buf); ! 180: if (strcmp(p, "remote") == 0) { ! 181: p += strlen(p)+1; ! 182: if (strcmp(p, "from") == 0) { ! 183: p += strlen(p)+1; ! 184: strcpy(buf, p); ! 185: strcat(buf, "!"); ! 186: return(buf+strlen(buf)); ! 187: } ! 188: } ! 189: } ! 190: garbled: ! 191: strcat(buf, "???!"); ! 192: return(buf+4); ! 193: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.