xref: /original-bsd/libexec/bugfiler/reply.c (revision f1324ba5)
1 /*
2  * Copyright (c) 1986, 1987 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)reply.c	5.6 (Berkeley) 06/29/88";
20 #endif /* not lint */
21 
22 #include <bug.h>
23 #include <sys/file.h>
24 #include <stdio.h>
25 
26 /*
27  * reply --
28  *	tell the user we got their silly little bug report
29  */
30 reply()
31 {
32 	register char	*C,			/* traveling pointer */
33 			*to;			/* who we're replying to */
34 	register int	afd,			/* ack file descriptor */
35 			rval;			/* return value */
36 	FILE	*pf,				/* pipe pointer */
37 		*popen();
38 	char	*index();
39 
40 	if (mailhead[RPLY_TAG].found) {
41 		for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
42 		if (*C)
43 			goto gotone;
44 	}
45 	if (mailhead[FROM_TAG].found) {
46 		for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
47 		if (*C)
48 			goto gotone;
49 	}
50 	if (mailhead[CFROM_TAG].found) {
51 		for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
52 		if (*C)
53 			goto gotone;
54 	}
55 	return;
56 
57 	/* if it's a foo <XXX>, get the XXX, else get foo (first string) */
58 gotone:	if (to = index(C, '<'))
59 		for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
60 	else {
61 		to = C;
62 		for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
63 	}
64 	*C = EOS;
65 
66 	if (!(pf = popen(MAIL_CMD, "w")))
67 		error("sendmail pipe failed.", CHN);
68 
69 	fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n", BUGS_HOME, BUGS_HOME, to);
70 	if (mailhead[SUBJ_TAG].found)
71 		fprintf(pf, "Subject: Re:%s", mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
72 	else
73 		fputs("Subject: Bug report acknowledgement.\n", pf);
74 	if (mailhead[DATE_TAG].found)
75 		fprintf(pf, "In-Acknowledgement-Of: Your message of %s", mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
76 	if (mailhead[MSG_TAG].found)
77 		fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
78 	fputs("Precedence: bulk\n\n", pf);	/* vacation(1) uses this... */
79 	fflush(pf);
80 
81 	(void)sprintf(bfr, "%s/%s", dir, ACK_FILE);
82 	if ((afd = open(bfr, O_RDONLY, 0)) >= 0) {
83 		while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
84 			(void)write(fileno(pf), bfr, rval);
85 		(void)close(afd);
86 	}
87 	pclose(pf);
88 }
89