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