1 /*
2 * Copyright (c) 1986, 1987, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)redist.c 8.1 (Berkeley) 06/04/93";
10 #endif /* not lint */
11
12 #include <sys/param.h>
13
14 #include <ctype.h>
15 #include <dirent.h>
16 #include <stdio.h>
17 #include <string.h>
18
19 #include "bug.h"
20 #include "pathnames.h"
21 #include "extern.h"
22
23 /*
24 * redist --
25 * Redistribute a bug report to those people indicated in the
26 * redistribution list file.
27 */
28 void
redist()29 redist()
30 {
31 extern FILE *dfp; /* dist file fp */
32 extern char pfile[]; /* permanent bug file */
33 register char *C1, *C2;
34 FILE *pf;
35 int group;
36
37 (void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
38 if (!freopen(bfr, "r", stdin))
39 return;
40 for (pf = NULL, group = 0; fgets(bfr, sizeof(bfr), stdin);) {
41 if (C1 = strchr(bfr, '\n'))
42 *C1 = '\0';
43 nextline: if (*bfr == COMMENT ||
44 isspace(*bfr) || !(C1 = index(bfr, ':')))
45 continue;
46 *C1 = EOS;
47 if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
48 for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
49 if (!*C1) /* if empty list */
50 continue;
51 if (!pf) {
52 if (!(pf = popen(MAIL_CMD, "w")))
53 error("sendmail pipe failed.", CHN);
54 if (mailhead[SUBJ_TAG].found)
55 fprintf(pf,
56 "%s", mailhead[SUBJ_TAG].line);
57 else
58 fprintf(pf,
59 "Subject: Untitled Bug Report\n");
60 if (!mailhead[TO_TAG].line) {
61 if (mailhead[APPAR_TO_TAG].line)
62 fprintf(pf, "To%s",
63 strchr(mailhead[APPAR_TO_TAG].line,
64 ':'));
65 else
66 fprintf(pf, "To: %s\n", BUGS_ID);
67 }
68 fputs("Resent-To: ", pf);
69 }
70 /*
71 * write out first entry, then succeeding entries
72 * backward compatible, handles back slashes at end
73 * of line
74 */
75 if (group++)
76 fputs(", ", pf);
77 for (;;) {
78 if (C2 = strchr(C1, '\\'))
79 *C2 = EOS;
80 fputs(C1, pf);
81 if (!fgets(bfr, sizeof(bfr), stdin))
82 break;
83 if (C1 = strchr(bfr, '\n'))
84 *C1 = '\0';
85 if (*bfr != ' ' && *bfr != '\t')
86 goto nextline;
87 for (C1 = bfr;
88 *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
89 }
90 }
91 }
92 if (!pf)
93 return;
94
95 putc('\n', pf);
96
97 rewind(dfp);
98 /* add Reference header and copy bug report out */
99 while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
100 fputs(bfr, pf);
101 fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
102 while (fgets(bfr, sizeof(bfr), dfp))
103 fputs(bfr, pf);
104 (void)pclose(pf);
105 }
106