-struct header *findheader();
-
-process()
-{
- register struct header *hp;
- register char *cp;
- register int c;
- char *info;
- int state, tmp;
- FILE *tfp, *fs;
-
- /*
- * Insure all headers are in a consistent
- * state. Anything left there is free'd.
- */
- for (hp = headers; hp->h_tag; hp++) {
- hp->h_flags &= ~H_FND;
- if (hp->h_info) {
- free(hp->h_info);
- hp->h_info = 0;
- }
- }
- /*
- * Read the report and make a copy. Must conform to RFC822 and
- * be of the form... <tag>: <info>
- * Note that the input is expected to be in mh mail format
- * (i.e., messages are separated by lines of ^A's).
- */
- while ((c = getchar()) == '\001' && peekc(stdin) == '\001')
- while (getchar() != '\n')
- ;
- if (c == EOF)
- return(0); /* all done */
-
- mktemp(tmpname);
- if ((tmp = creat(tmpname, msg_prot)) < 0) {
- fprintf(stderr, "cannont create %s\n", tmpname);
- exit(1);
- }
- if ((tfp = fdopen(tmp, "w")) == NULL) {
- fprintf(stderr, "cannot fdopen temp file\n");
- exit(1);
- }
-
- for (state = FLD; state != EOF && state != EOM; c = getchar()) {
- switch (state) {
- case FLD:
- if (c == '\n' || c == '-')
- goto body;
- for (cp = buf; c != ':'; c = getchar()) {
- if (cp < buf+sizeof(buf)-1 && c != '\n' && c != EOF) {
- *cp++ = c;
- continue;
- }
- *cp = '\0';
- fputs(buf, tfp);
- state = EOF;
- while (c != EOF) {
- if (c == '\n')
- if ((tmp = peekc(stdin)) == EOF)
- break;
- else if (tmp == '\001') {
- state = EOM;
- break;
- }
- putc(c, tfp);
- c = getchar();
- }
- fclose(tfp);
- goto badfmt;
- }
- *cp = '\0';
- fprintf(tfp, "%s:", buf);
- hp = findheader(buf, state);
-
- for (cp = buf; ; ) {
- if (cp >= buf+sizeof(buf)-1) {
- fprintf(stderr, "field truncated\n");
- while ((c = getchar()) != EOF && c != '\n')
- putc(c, tfp);
- }
- if ((c = getchar()) == EOF) {
- state = EOF;
- break;
- }
- putc(c, tfp);
- *cp++ = c;
- if (c == '\n')
- if ((c = peekc(stdin)) != ' ' && c != '\t') {
- if (c == EOF)
- state = EOF;
- else if (c == '\001')
- state = EOM;
- break;
- }
- }
- *cp = '\0';
- cp = buf;
- break;
-
- body:
- state = BODY;
- case BODY:
- for (cp = buf; ; c = getchar()) {
- if (c == EOF) {
- state = EOF;
- break;
- }
- if (c == '\001' && peekc(stdin) == '\001') {
- state = EOM;
- break;
- }
- putc(c, tfp);
- *cp++ = c;
- if (cp >= buf+sizeof(buf)-1 || c == '\n')
- break;
- }
- *cp = '\0';
- if ((cp = index(buf, ':')) == NULL)
- continue;
- *cp++ = '\0';
- hp = findheader(buf, state);
- }
-
- /*
- * Don't save the info if the header wasn't found, we don't
- * care about the info, or the header is repeated.
- */
- if (hp == NULL || !(hp->h_flags & H_SAV) || hp->h_info)
- continue;
- while (isspace(*cp))
- cp++;
- if (*cp) {
- info = cp;
- while (*cp++);
- cp--;
- while (isspace(cp[-1]))
- *--cp = '\0';
- hp->h_info = (char *) malloc(strlen(info) + 1);
- if (hp->h_info == NULL) {
- fprintf(stderr, "ran out of memory\n");
- continue;
- }
- strcpy(hp->h_info, info);
- if (hp == INDEX)
- chkindex(hp);
- }
- }
- fclose(tfp);
- /*
- * Verify all the required pieces of information
- * are present.
- */
- for (hp = headers; hp->h_tag; hp++) {
- /*
- * Mail the bug report back to the sender with a note
- * explaining they must conform to the specification.
- */
- if ((hp->h_flags & H_REQ) && !(hp->h_flags & H_FND)) {
- if (debug)
- printf("Missing %s\n", hp->h_tag);
- badfmt:
- reply(FROM_I, errfile, tmpname);
- file(tmpname, "errors");
- return(state == EOM);
- }
- }
- /*
- * Acknowledge receipt.
- */
- reply(FROM_I, ackfile, (char *)0);
- file(tmpname, folder);
- /*
- * Append information about the new bug report
- * to the summary file.
- */
- if ((fs = fopen(sumfile, "a")) == NULL)
- fprintf(stderr, "Can't open %s\n", sumfile);
- else {
- fprintf(fs, "%14.14s/%-3d ", folder, num);
- fprintf(fs, "%-51.51s Recv\n", INDEX_I);
- fprintf(fs, "\t\t %-51.51s\n", SUBJECT_I);
- }
- fclose(fs);
- return(state == EOM);
-}