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