xref: /csrg-svn/libexec/bugfiler/redist.c (revision 34910)
130158Sbostic /*
233416Sbostic  * Copyright (c) 1986, 1987 Regents of the University of California.
333416Sbostic  * All rights reserved.
433416Sbostic  *
533416Sbostic  * Redistribution and use in source and binary forms are permitted
6*34910Sbostic  * provided that the above copyright notice and this paragraph are
7*34910Sbostic  * duplicated in all such forms and that any documentation,
8*34910Sbostic  * advertising materials, and other materials related to such
9*34910Sbostic  * distribution and use acknowledge that the software was developed
10*34910Sbostic  * by the University of California, Berkeley.  The name of the
11*34910Sbostic  * University may not be used to endorse or promote products derived
12*34910Sbostic  * from this software without specific prior written permission.
13*34910Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*34910Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*34910Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1630158Sbostic  */
1730158Sbostic 
1830158Sbostic #ifndef lint
19*34910Sbostic static char sccsid[] = "@(#)redist.c	5.8 (Berkeley) 06/29/88";
2033416Sbostic #endif /* not lint */
2130158Sbostic 
2230158Sbostic #include <sys/file.h>
2330158Sbostic #include <stdio.h>
2433024Sbostic #include <ctype.h>
2530158Sbostic #include <bug.h>
2630158Sbostic 
2730158Sbostic /*
2830158Sbostic  * redist --
2930158Sbostic  *	Redistribute a bug report to those people indicated in the
3030158Sbostic  *	redistribution list file.
3130158Sbostic  */
3230158Sbostic redist()
3330158Sbostic {
3430890Sbostic 	extern FILE	*dfp;		/* dist file fp */
3530890Sbostic 	extern char	pfile[];	/* permanent bug file */
3633024Sbostic 	register char	*C1, *C2;
3733024Sbostic 	FILE	*pf, *popen();
3833024Sbostic 	int	group;
3930890Sbostic 	char	*index();
4030158Sbostic 
4133024Sbostic 	(void)sprintf(bfr, "%s/%s", dir, DIST_FILE);
4230890Sbostic 	if (!freopen(bfr, "r", stdin))
4330158Sbostic 		return;
4433024Sbostic 	for (pf = NULL, group = 0; gets(bfr);) {
4533024Sbostic 		if (*bfr == COMMENT || isspace(*bfr) || !(C1 = index(bfr, ':')))
4630158Sbostic 			continue;
4730158Sbostic 		*C1 = EOS;
4833024Sbostic 		if (!strcmp(bfr, folder) || !strcmp(bfr, "all")) {
4933024Sbostic 			for (++C1; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
5033024Sbostic 			if (!*C1)			/* if empty list */
5133024Sbostic 				continue;
5233024Sbostic 			if (!pf) {
5333024Sbostic 				if (!(pf = popen(MAIL_CMD, "w")))
5433024Sbostic 					error("sendmail pipe failed.", CHN);
5533024Sbostic 				if (mailhead[SUBJ_TAG].found)
5633024Sbostic 					fprintf(pf, "%s", mailhead[SUBJ_TAG].line);
5733024Sbostic 				else
5833024Sbostic 					fputs("Subject: Untitled Bug Report\n", pf);
5933928Skarels 				if (!mailhead[TO_TAG].line) {
6033928Skarels 					if (mailhead[APPAR_TO_TAG].line)
6133928Skarels 					    fprintf(pf, "To%s",
6233928Skarels 					      index(mailhead[APPAR_TO_TAG].line,
6333928Skarels 					      ':'));
6433928Skarels 					else
6533928Skarels 					    fprintf(pf, "To: %s\n",  BUGS_ID);
6633928Skarels 				}
6733024Sbostic 				fputs("Resent-To: ", pf);
6833024Sbostic 			}
6933024Sbostic 			/*
7033024Sbostic 			 * write out first entry, then succeeding entries
7133024Sbostic 			 * backward compatible, handles back slashes at end
7233024Sbostic 			 * of line
7333024Sbostic 			 */
7433024Sbostic 			if (group++)
7533024Sbostic 				fputs(", ", pf);
7633024Sbostic 			for (;;) {
7733024Sbostic 				if (C2 = index(C1, '\\'))
7833024Sbostic 					*C2 = EOS;
7933024Sbostic 				fputs(C1, pf);
8033024Sbostic 				if (!gets(bfr) || *bfr != ' ' && *bfr != '\t')
8133024Sbostic 					break;
8233024Sbostic 				for (C1 = bfr; *C1 && (*C1 == ' ' || *C1 == '\t'); ++C1);
8333024Sbostic 			}
8433024Sbostic 		}
8530158Sbostic 	}
8633024Sbostic 	if (!pf)
8730158Sbostic 		return;
8830158Sbostic 
8930890Sbostic 	putc('\n', pf);
9030158Sbostic 
9130890Sbostic 	rewind(dfp);
9233024Sbostic 	/* add Reference header and copy bug report out */
9333024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp) && *bfr != '\n')
9433024Sbostic 		fputs(bfr, pf);
9533024Sbostic 	fprintf(pf, "\n%sReference: %s\n\n", mailhead[INDX_TAG].line, pfile);
9633024Sbostic 	while (fgets(bfr, sizeof(bfr), dfp))
9733024Sbostic 		fputs(bfr, pf);
9830890Sbostic 	(void)pclose(pf);
9930158Sbostic }
100