xref: /csrg-svn/libexec/bugfiler/reply.c (revision 34910)
130159Sbostic /*
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.
1630159Sbostic  */
1730159Sbostic 
1830159Sbostic #ifndef lint
19*34910Sbostic static char sccsid[] = "@(#)reply.c	5.6 (Berkeley) 06/29/88";
2033416Sbostic #endif /* not lint */
2130159Sbostic 
2230159Sbostic #include <bug.h>
2330159Sbostic #include <sys/file.h>
2430159Sbostic #include <stdio.h>
2530159Sbostic 
2630159Sbostic /*
2730159Sbostic  * reply --
2830890Sbostic  *	tell the user we got their silly little bug report
2930159Sbostic  */
3030159Sbostic reply()
3130159Sbostic {
3230159Sbostic 	register char	*C,			/* traveling pointer */
3330159Sbostic 			*to;			/* who we're replying to */
3430159Sbostic 	register int	afd,			/* ack file descriptor */
3530159Sbostic 			rval;			/* return value */
3630159Sbostic 	FILE	*pf,				/* pipe pointer */
3730159Sbostic 		*popen();
3830890Sbostic 	char	*index();
3930159Sbostic 
4030159Sbostic 	if (mailhead[RPLY_TAG].found) {
4130159Sbostic 		for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
4230159Sbostic 		if (*C)
4330159Sbostic 			goto gotone;
4430159Sbostic 	}
4530159Sbostic 	if (mailhead[FROM_TAG].found) {
4630159Sbostic 		for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
4730159Sbostic 		if (*C)
4830159Sbostic 			goto gotone;
4930159Sbostic 	}
5030159Sbostic 	if (mailhead[CFROM_TAG].found) {
5130159Sbostic 		for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
5230159Sbostic 		if (*C)
5330159Sbostic 			goto gotone;
5430159Sbostic 	}
5530159Sbostic 	return;
5630159Sbostic 
5730159Sbostic 	/* if it's a foo <XXX>, get the XXX, else get foo (first string) */
5830890Sbostic gotone:	if (to = index(C, '<'))
5930159Sbostic 		for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
6030159Sbostic 	else {
6130159Sbostic 		to = C;
6230159Sbostic 		for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
6330159Sbostic 	}
6430159Sbostic 	*C = EOS;
6530159Sbostic 
6630890Sbostic 	if (!(pf = popen(MAIL_CMD, "w")))
6730890Sbostic 		error("sendmail pipe failed.", CHN);
6830159Sbostic 
6930890Sbostic 	fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n", BUGS_HOME, BUGS_HOME, to);
7030159Sbostic 	if (mailhead[SUBJ_TAG].found)
7130890Sbostic 		fprintf(pf, "Subject: Re:%s", mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
7230159Sbostic 	else
7330890Sbostic 		fputs("Subject: Bug report acknowledgement.\n", pf);
7430159Sbostic 	if (mailhead[DATE_TAG].found)
7530890Sbostic 		fprintf(pf, "In-Acknowledgement-Of: Your message of %s", mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
7630159Sbostic 	if (mailhead[MSG_TAG].found)
7730890Sbostic 		fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
7831910Sbostic 	fputs("Precedence: bulk\n\n", pf);	/* vacation(1) uses this... */
7930159Sbostic 	fflush(pf);
8030159Sbostic 
8132654Sbostic 	(void)sprintf(bfr, "%s/%s", dir, ACK_FILE);
8232654Sbostic 	if ((afd = open(bfr, O_RDONLY, 0)) >= 0) {
8330890Sbostic 		while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
8430890Sbostic 			(void)write(fileno(pf), bfr, rval);
8530890Sbostic 		(void)close(afd);
8630159Sbostic 	}
8730159Sbostic 	pclose(pf);
8830159Sbostic }
89