130159Sbostic /*
2*61420Sbostic * Copyright (c) 1986, 1987, 1993
3*61420Sbostic * The Regents of the University of California. All rights reserved.
433416Sbostic *
542663Sbostic * %sccs.include.redist.c%
630159Sbostic */
730159Sbostic
830159Sbostic #ifndef lint
9*61420Sbostic static char sccsid[] = "@(#)reply.c 8.1 (Berkeley) 06/04/93";
1033416Sbostic #endif /* not lint */
1130159Sbostic
1246667Sbostic #include <sys/param.h>
1360083Sbostic
1460083Sbostic #include <dirent.h>
1546667Sbostic #include <fcntl.h>
1630159Sbostic #include <stdio.h>
1746667Sbostic #include <string.h>
1860083Sbostic #include <unistd.h>
1960083Sbostic
2046667Sbostic #include "bug.h"
2160083Sbostic #include "extern.h"
2237887Sbostic #include "pathnames.h"
2330159Sbostic
2430159Sbostic /*
2530159Sbostic * reply --
2630890Sbostic * tell the user we got their silly little bug report
2730159Sbostic */
2860083Sbostic void
reply()2930159Sbostic reply()
3030159Sbostic {
3130159Sbostic register char *C, /* traveling pointer */
3230159Sbostic *to; /* who we're replying to */
3330159Sbostic register int afd, /* ack file descriptor */
3430159Sbostic rval; /* return value */
3560083Sbostic FILE *pf; /* pipe pointer */
3630159Sbostic
3730159Sbostic if (mailhead[RPLY_TAG].found) {
3860083Sbostic for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;
3960083Sbostic *C != '\n' && (*C == ' ' || *C == '\t');++C);
4030159Sbostic if (*C)
4130159Sbostic goto gotone;
4230159Sbostic }
4330159Sbostic if (mailhead[FROM_TAG].found) {
4460083Sbostic for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;
4560083Sbostic *C != '\n' && (*C == ' ' || *C == '\t');++C);
4630159Sbostic if (*C)
4730159Sbostic goto gotone;
4830159Sbostic }
4930159Sbostic if (mailhead[CFROM_TAG].found) {
5060083Sbostic for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;
5160083Sbostic *C != '\n' && (*C == ' ' || *C == '\t');++C);
5230159Sbostic if (*C)
5330159Sbostic goto gotone;
5430159Sbostic }
5530159Sbostic return;
5630159Sbostic
5730159Sbostic /* if it's a foo <XXX>, get the XXX, else get foo (first string) */
5860083Sbostic gotone: if (to = strchr(C, '<'))
5960083Sbostic for (C = ++to;
6060083Sbostic *C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
6130159Sbostic else {
6230159Sbostic to = C;
6330159Sbostic for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
6430159Sbostic }
6530159Sbostic *C = EOS;
6630159Sbostic
6730890Sbostic if (!(pf = popen(MAIL_CMD, "w")))
6830890Sbostic error("sendmail pipe failed.", CHN);
6930159Sbostic
7060083Sbostic fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n",
7160083Sbostic BUGS_HOME, BUGS_HOME, to);
7230159Sbostic if (mailhead[SUBJ_TAG].found)
7360083Sbostic fprintf(pf, "Subject: Re:%s",
7460083Sbostic mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
7530159Sbostic else
7630890Sbostic fputs("Subject: Bug report acknowledgement.\n", pf);
7730159Sbostic if (mailhead[DATE_TAG].found)
7860083Sbostic fprintf(pf, "In-Acknowledgement-Of: Your message of %s",
7960083Sbostic mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
8030159Sbostic if (mailhead[MSG_TAG].found)
8130890Sbostic fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
8231910Sbostic fputs("Precedence: bulk\n\n", pf); /* vacation(1) uses this... */
8330159Sbostic fflush(pf);
8430159Sbostic
8532654Sbostic (void)sprintf(bfr, "%s/%s", dir, ACK_FILE);
8632654Sbostic if ((afd = open(bfr, O_RDONLY, 0)) >= 0) {
8730890Sbostic while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
8830890Sbostic (void)write(fileno(pf), bfr, rval);
8930890Sbostic (void)close(afd);
9030159Sbostic }
9130159Sbostic pclose(pf);
9230159Sbostic }
93