xref: /csrg-svn/libexec/bugfiler/reply.c (revision 37887)
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
634910Sbostic  * provided that the above copyright notice and this paragraph are
734910Sbostic  * duplicated in all such forms and that any documentation,
834910Sbostic  * advertising materials, and other materials related to such
934910Sbostic  * distribution and use acknowledge that the software was developed
1034910Sbostic  * by the University of California, Berkeley.  The name of the
1134910Sbostic  * University may not be used to endorse or promote products derived
1234910Sbostic  * from this software without specific prior written permission.
1334910Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434910Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534910Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1630159Sbostic  */
1730159Sbostic 
1830159Sbostic #ifndef lint
19*37887Sbostic static char sccsid[] = "@(#)reply.c	5.7 (Berkeley) 05/11/89";
2033416Sbostic #endif /* not lint */
2130159Sbostic 
2230159Sbostic #include <bug.h>
2330159Sbostic #include <sys/file.h>
2430159Sbostic #include <stdio.h>
25*37887Sbostic #include "pathnames.h"
2630159Sbostic 
2730159Sbostic /*
2830159Sbostic  * reply --
2930890Sbostic  *	tell the user we got their silly little bug report
3030159Sbostic  */
3130159Sbostic reply()
3230159Sbostic {
3330159Sbostic 	register char	*C,			/* traveling pointer */
3430159Sbostic 			*to;			/* who we're replying to */
3530159Sbostic 	register int	afd,			/* ack file descriptor */
3630159Sbostic 			rval;			/* return value */
3730159Sbostic 	FILE	*pf,				/* pipe pointer */
3830159Sbostic 		*popen();
3930890Sbostic 	char	*index();
4030159Sbostic 
4130159Sbostic 	if (mailhead[RPLY_TAG].found) {
4230159Sbostic 		for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
4330159Sbostic 		if (*C)
4430159Sbostic 			goto gotone;
4530159Sbostic 	}
4630159Sbostic 	if (mailhead[FROM_TAG].found) {
4730159Sbostic 		for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
4830159Sbostic 		if (*C)
4930159Sbostic 			goto gotone;
5030159Sbostic 	}
5130159Sbostic 	if (mailhead[CFROM_TAG].found) {
5230159Sbostic 		for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
5330159Sbostic 		if (*C)
5430159Sbostic 			goto gotone;
5530159Sbostic 	}
5630159Sbostic 	return;
5730159Sbostic 
5830159Sbostic 	/* if it's a foo <XXX>, get the XXX, else get foo (first string) */
5930890Sbostic gotone:	if (to = index(C, '<'))
6030159Sbostic 		for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
6130159Sbostic 	else {
6230159Sbostic 		to = C;
6330159Sbostic 		for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
6430159Sbostic 	}
6530159Sbostic 	*C = EOS;
6630159Sbostic 
6730890Sbostic 	if (!(pf = popen(MAIL_CMD, "w")))
6830890Sbostic 		error("sendmail pipe failed.", CHN);
6930159Sbostic 
7030890Sbostic 	fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n", BUGS_HOME, BUGS_HOME, to);
7130159Sbostic 	if (mailhead[SUBJ_TAG].found)
7230890Sbostic 		fprintf(pf, "Subject: Re:%s", mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
7330159Sbostic 	else
7430890Sbostic 		fputs("Subject: Bug report acknowledgement.\n", pf);
7530159Sbostic 	if (mailhead[DATE_TAG].found)
7630890Sbostic 		fprintf(pf, "In-Acknowledgement-Of: Your message of %s", mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
7730159Sbostic 	if (mailhead[MSG_TAG].found)
7830890Sbostic 		fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
7931910Sbostic 	fputs("Precedence: bulk\n\n", pf);	/* vacation(1) uses this... */
8030159Sbostic 	fflush(pf);
8130159Sbostic 
8232654Sbostic 	(void)sprintf(bfr, "%s/%s", dir, ACK_FILE);
8332654Sbostic 	if ((afd = open(bfr, O_RDONLY, 0)) >= 0) {
8430890Sbostic 		while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
8530890Sbostic 			(void)write(fileno(pf), bfr, rval);
8630890Sbostic 		(void)close(afd);
8730159Sbostic 	}
8830159Sbostic 	pclose(pf);
8930159Sbostic }
90