xref: /original-bsd/libexec/bugfiler/redist.c (revision 4cfdb854)
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[] = "@(#)redist.c	5.10 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 #include <sys/file.h>
13 #include <stdio.h>
14 #include <ctype.h>
15 #include <bug.h>
16 #include "pathnames.h"
17 
18 /*
19  * redist --
20  *	Redistribute a bug report to those people indicated in the
21  *	redistribution list file.
22  */
23 redist()
24 {
25 	extern FILE	*dfp;		/* dist file fp */
26 	extern char	pfile[];	/* permanent bug file */
27 	register char	*C1, *C2;
28 	FILE	*pf, *popen();
29 	int	group;
30 	char	*index();
31 
32 	(void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
33 	if (!freopen(bfr, "r", stdin))
34 		return;
35 	for (pf = NULL, group = 0; gets(bfr);) {
36 		if (*bfr == COMMENT || isspace(*bfr) || !(C1 = index(bfr, ':')))
37 			continue;
38 		*C1 = EOS;
39 		if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
40 			for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
41 			if (!*C1)			/* if empty list */
42 				continue;
43 			if (!pf) {
44 				if (!(pf = popen(MAIL_CMD, "w")))
45 					error("sendmail pipe failed.", CHN);
46 				if (mailhead[SUBJ_TAG].found)
47 					fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
48 				else
49 					fputs("Subject: Untitled Bug Report\n", pf);
50 				if (!mailhead[TO_TAG].line) {
51 					if (mailhead[APPAR_TO_TAG].line)
52 					    fprintf(pf, "To%s",
53 					      index(mailhead[APPAR_TO_TAG].line,
54 					      ':'));
55 					else
56 					    fprintf(pf, "To: %s\n",  BUGS_ID);
57 				}
58 				fputs("Resent-To: ", pf);
59 			}
60 			/*
61 			 * write out first entry, then succeeding entries
62 			 * backward compatible, handles back slashes at end
63 			 * of line
64 			 */
65 			if (group++)
66 				fputs(", ", pf);
67 			for (;;) {
68 				if (C2 = index(C1, '\\'))
69 					*C2 = EOS;
70 				fputs(C1, pf);
71 				if (!gets(bfr) || *bfr != ' ' && *bfr != '\t')
72 					break;
73 				for (C1 = bfr; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
74 			}
75 		}
76 	}
77 	if (!pf)
78 		return;
79 
80 	putc('\n', pf);
81 
82 	rewind(dfp);
83 	/* add Reference header and copy bug report out */
84 	while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
85 		fputs(bfr, pf);
86 	fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
87 	while (fgets(bfr, sizeof(bfr), dfp))
88 		fputs(bfr, pf);
89 	(void)pclose(pf);
90 }
91