1e974dd97Sbostic /*
2*92e05a12Sbostic * Copyright (c) 1986, 1987, 1993
3*92e05a12Sbostic * The Regents of the University of California. All rights reserved.
437c8c8e2Sbostic *
56472dbc6Sbostic * %sccs.include.redist.c%
6e974dd97Sbostic */
7e974dd97Sbostic
8e974dd97Sbostic #ifndef lint
9*92e05a12Sbostic static char sccsid[] = "@(#)redist.c 8.1 (Berkeley) 06/04/93";
1037c8c8e2Sbostic #endif /* not lint */
11e974dd97Sbostic
12054717d4Sbostic #include <sys/param.h>
13c48498dbSbostic
14c48498dbSbostic #include <ctype.h>
15054717d4Sbostic #include <dirent.h>
16e974dd97Sbostic #include <stdio.h>
17054717d4Sbostic #include <string.h>
18c48498dbSbostic
19054717d4Sbostic #include "bug.h"
203224629dSbostic #include "pathnames.h"
21c48498dbSbostic #include "extern.h"
22e974dd97Sbostic
23e974dd97Sbostic /*
24e974dd97Sbostic * redist --
25e974dd97Sbostic * Redistribute a bug report to those people indicated in the
26e974dd97Sbostic * redistribution list file.
27e974dd97Sbostic */
28c48498dbSbostic void
redist()29e974dd97Sbostic redist()
30e974dd97Sbostic {
313212f6deSbostic extern FILE *dfp; /* dist file fp */
323212f6deSbostic extern char pfile[]; /* permanent bug file */
33962c64f5Sbostic register char *C1, *C2;
34c48498dbSbostic FILE *pf;
35962c64f5Sbostic int group;
36e974dd97Sbostic
37962c64f5Sbostic (void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
383212f6deSbostic if (!freopen(bfr, "r", stdin))
39e974dd97Sbostic return;
400e34a5eeSbostic for (pf = NULL, group = 0; fgets(bfr, sizeof(bfr), stdin);) {
41c48498dbSbostic if (C1 = strchr(bfr, '\n'))
420e34a5eeSbostic *C1 = '\0';
43c48498dbSbostic nextline: if (*bfr == COMMENT ||
44c48498dbSbostic isspace(*bfr) || !(C1 = index(bfr, ':')))
45e974dd97Sbostic continue;
46e974dd97Sbostic *C1 = EOS;
47962c64f5Sbostic if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
48e974dd97Sbostic for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
49962c64f5Sbostic if (!*C1) /* if empty list */
50962c64f5Sbostic continue;
51962c64f5Sbostic if (!pf) {
52e974dd97Sbostic if (!(pf = popen(MAIL_CMD, "w")))
53e974dd97Sbostic error("sendmail pipe failed.", CHN);
54e974dd97Sbostic if (mailhead[SUBJ_TAG].found)
550e34a5eeSbostic fprintf(pf,
560e34a5eeSbostic "%s", mailhead[SUBJ_TAG].line);
57e974dd97Sbostic else
580e34a5eeSbostic fprintf(pf,
590e34a5eeSbostic "Subject: Untitled Bug Report\n");
60729f8592Skarels if (!mailhead[TO_TAG].line) {
61729f8592Skarels if (mailhead[APPAR_TO_TAG].line)
62729f8592Skarels fprintf(pf, "To%s",
63c48498dbSbostic strchr(mailhead[APPAR_TO_TAG].line,
64729f8592Skarels ':'));
65729f8592Skarels else
66729f8592Skarels fprintf(pf, "To: %s\n", BUGS_ID);
67729f8592Skarels }
68e974dd97Sbostic fputs("Resent-To: ", pf);
69962c64f5Sbostic }
70e974dd97Sbostic /*
71e974dd97Sbostic * write out first entry, then succeeding entries
72962c64f5Sbostic * backward compatible, handles back slashes at end
73962c64f5Sbostic * of line
74e974dd97Sbostic */
75962c64f5Sbostic if (group++)
76962c64f5Sbostic fputs(", ", pf);
77e974dd97Sbostic for (;;) {
78c48498dbSbostic if (C2 = strchr(C1, '\\'))
79e974dd97Sbostic *C2 = EOS;
80e974dd97Sbostic fputs(C1, pf);
810e34a5eeSbostic if (!fgets(bfr, sizeof(bfr), stdin))
82e974dd97Sbostic break;
83c48498dbSbostic if (C1 = strchr(bfr, '\n'))
840e34a5eeSbostic *C1 = '\0';
850e34a5eeSbostic if (*bfr != ' ' && *bfr != '\t')
860e34a5eeSbostic goto nextline;
870e34a5eeSbostic for (C1 = bfr;
880e34a5eeSbostic *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
89e974dd97Sbostic }
90962c64f5Sbostic }
91962c64f5Sbostic }
92962c64f5Sbostic if (!pf)
93962c64f5Sbostic return;
94962c64f5Sbostic
953212f6deSbostic putc('\n', pf);
96e974dd97Sbostic
973212f6deSbostic rewind(dfp);
98962c64f5Sbostic /* add Reference header and copy bug report out */
99962c64f5Sbostic while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
100962c64f5Sbostic fputs(bfr, pf);
101962c64f5Sbostic fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
102962c64f5Sbostic while (fgets(bfr, sizeof(bfr), dfp))
103e974dd97Sbostic fputs(bfr, pf);
1043212f6deSbostic (void)pclose(pf);
105e974dd97Sbostic }
106