xref: /original-bsd/libexec/bugfiler/reply.c (revision 7a8f01dc)
1 /*
2  * Copyright (c) 1986, 1987 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)reply.c	5.8 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 #include <bug.h>
13 #include <sys/file.h>
14 #include <stdio.h>
15 #include "pathnames.h"
16 
17 /*
18  * reply --
19  *	tell the user we got their silly little bug report
20  */
21 reply()
22 {
23 	register char	*C,			/* traveling pointer */
24 			*to;			/* who we're replying to */
25 	register int	afd,			/* ack file descriptor */
26 			rval;			/* return value */
27 	FILE	*pf,				/* pipe pointer */
28 		*popen();
29 	char	*index();
30 
31 	if (mailhead[RPLY_TAG].found) {
32 		for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
33 		if (*C)
34 			goto gotone;
35 	}
36 	if (mailhead[FROM_TAG].found) {
37 		for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
38 		if (*C)
39 			goto gotone;
40 	}
41 	if (mailhead[CFROM_TAG].found) {
42 		for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
43 		if (*C)
44 			goto gotone;
45 	}
46 	return;
47 
48 	/* if it's a foo <XXX>, get the XXX, else get foo (first string) */
49 gotone:	if (to = index(C, '<'))
50 		for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
51 	else {
52 		to = C;
53 		for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
54 	}
55 	*C = EOS;
56 
57 	if (!(pf = popen(MAIL_CMD, "w")))
58 		error("sendmail pipe failed.", CHN);
59 
60 	fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n", BUGS_HOME, BUGS_HOME, to);
61 	if (mailhead[SUBJ_TAG].found)
62 		fprintf(pf, "Subject: Re:%s", mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
63 	else
64 		fputs("Subject: Bug report acknowledgement.\n", pf);
65 	if (mailhead[DATE_TAG].found)
66 		fprintf(pf, "In-Acknowledgement-Of: Your message of %s", mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
67 	if (mailhead[MSG_TAG].found)
68 		fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
69 	fputs("Precedence: bulk\n\n", pf);	/* vacation(1) uses this... */
70 	fflush(pf);
71 
72 	(void)sprintf(bfr, "%s/%s", dir, ACK_FILE);
73 	if ((afd = open(bfr, O_RDONLY, 0)) >= 0) {
74 		while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
75 			(void)write(fileno(pf), bfr, rval);
76 		(void)close(afd);
77 	}
78 	pclose(pf);
79 }
80