xref: /csrg-svn/libexec/bugfiler/reply.c (revision 42663)
130159Sbostic /*
233416Sbostic  * Copyright (c) 1986, 1987 Regents of the University of California.
333416Sbostic  * All rights reserved.
433416Sbostic  *
5*42663Sbostic  * %sccs.include.redist.c%
630159Sbostic  */
730159Sbostic 
830159Sbostic #ifndef lint
9*42663Sbostic static char sccsid[] = "@(#)reply.c	5.8 (Berkeley) 06/01/90";
1033416Sbostic #endif /* not lint */
1130159Sbostic 
1230159Sbostic #include <bug.h>
1330159Sbostic #include <sys/file.h>
1430159Sbostic #include <stdio.h>
1537887Sbostic #include "pathnames.h"
1630159Sbostic 
1730159Sbostic /*
1830159Sbostic  * reply --
1930890Sbostic  *	tell the user we got their silly little bug report
2030159Sbostic  */
2130159Sbostic reply()
2230159Sbostic {
2330159Sbostic 	register char	*C,			/* traveling pointer */
2430159Sbostic 			*to;			/* who we're replying to */
2530159Sbostic 	register int	afd,			/* ack file descriptor */
2630159Sbostic 			rval;			/* return value */
2730159Sbostic 	FILE	*pf,				/* pipe pointer */
2830159Sbostic 		*popen();
2930890Sbostic 	char	*index();
3030159Sbostic 
3130159Sbostic 	if (mailhead[RPLY_TAG].found) {
3230159Sbostic 		for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
3330159Sbostic 		if (*C)
3430159Sbostic 			goto gotone;
3530159Sbostic 	}
3630159Sbostic 	if (mailhead[FROM_TAG].found) {
3730159Sbostic 		for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
3830159Sbostic 		if (*C)
3930159Sbostic 			goto gotone;
4030159Sbostic 	}
4130159Sbostic 	if (mailhead[CFROM_TAG].found) {
4230159Sbostic 		for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
4330159Sbostic 		if (*C)
4430159Sbostic 			goto gotone;
4530159Sbostic 	}
4630159Sbostic 	return;
4730159Sbostic 
4830159Sbostic 	/* if it's a foo <XXX>, get the XXX, else get foo (first string) */
4930890Sbostic gotone:	if (to = index(C, '<'))
5030159Sbostic 		for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
5130159Sbostic 	else {
5230159Sbostic 		to = C;
5330159Sbostic 		for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
5430159Sbostic 	}
5530159Sbostic 	*C = EOS;
5630159Sbostic 
5730890Sbostic 	if (!(pf = popen(MAIL_CMD, "w")))
5830890Sbostic 		error("sendmail pipe failed.", CHN);
5930159Sbostic 
6030890Sbostic 	fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n", BUGS_HOME, BUGS_HOME, to);
6130159Sbostic 	if (mailhead[SUBJ_TAG].found)
6230890Sbostic 		fprintf(pf, "Subject: Re:%s", mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
6330159Sbostic 	else
6430890Sbostic 		fputs("Subject: Bug report acknowledgement.\n", pf);
6530159Sbostic 	if (mailhead[DATE_TAG].found)
6630890Sbostic 		fprintf(pf, "In-Acknowledgement-Of: Your message of %s", mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
6730159Sbostic 	if (mailhead[MSG_TAG].found)
6830890Sbostic 		fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
6931910Sbostic 	fputs("Precedence: bulk\n\n", pf);	/* vacation(1) uses this... */
7030159Sbostic 	fflush(pf);
7130159Sbostic 
7232654Sbostic 	(void)sprintf(bfr, "%s/%s", dir, ACK_FILE);
7332654Sbostic 	if ((afd = open(bfr, O_RDONLY, 0)) >= 0) {
7430890Sbostic 		while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
7530890Sbostic 			(void)write(fileno(pf), bfr, rval);
7630890Sbostic 		(void)close(afd);
7730159Sbostic 	}
7830159Sbostic 	pclose(pf);
7930159Sbostic }
80