xref: /csrg-svn/libexec/bugfiler/reply.c (revision 33416)
130159Sbostic /*
2*33416Sbostic  * Copyright (c) 1986, 1987 Regents of the University of California.
3*33416Sbostic  * All rights reserved.
4*33416Sbostic  *
5*33416Sbostic  * Redistribution and use in source and binary forms are permitted
6*33416Sbostic  * provided that this notice is preserved and that due credit is given
7*33416Sbostic  * to the University of California at Berkeley. The name of the University
8*33416Sbostic  * may not be used to endorse or promote products derived from this
9*33416Sbostic  * software without specific prior written permission. This software
10*33416Sbostic  * is provided ``as is'' without express or implied warranty.
1130159Sbostic  */
1230159Sbostic 
1330159Sbostic #ifndef lint
14*33416Sbostic static char sccsid[] = "@(#)reply.c	5.5 (Berkeley) 02/01/88";
15*33416Sbostic #endif /* not lint */
1630159Sbostic 
1730159Sbostic #include <bug.h>
1830159Sbostic #include <sys/file.h>
1930159Sbostic #include <stdio.h>
2030159Sbostic 
2130159Sbostic /*
2230159Sbostic  * reply --
2330890Sbostic  *	tell the user we got their silly little bug report
2430159Sbostic  */
2530159Sbostic reply()
2630159Sbostic {
2730159Sbostic 	register char	*C,			/* traveling pointer */
2830159Sbostic 			*to;			/* who we're replying to */
2930159Sbostic 	register int	afd,			/* ack file descriptor */
3030159Sbostic 			rval;			/* return value */
3130159Sbostic 	FILE	*pf,				/* pipe pointer */
3230159Sbostic 		*popen();
3330890Sbostic 	char	*index();
3430159Sbostic 
3530159Sbostic 	if (mailhead[RPLY_TAG].found) {
3630159Sbostic 		for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
3730159Sbostic 		if (*C)
3830159Sbostic 			goto gotone;
3930159Sbostic 	}
4030159Sbostic 	if (mailhead[FROM_TAG].found) {
4130159Sbostic 		for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
4230159Sbostic 		if (*C)
4330159Sbostic 			goto gotone;
4430159Sbostic 	}
4530159Sbostic 	if (mailhead[CFROM_TAG].found) {
4630159Sbostic 		for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
4730159Sbostic 		if (*C)
4830159Sbostic 			goto gotone;
4930159Sbostic 	}
5030159Sbostic 	return;
5130159Sbostic 
5230159Sbostic 	/* if it's a foo <XXX>, get the XXX, else get foo (first string) */
5330890Sbostic gotone:	if (to = index(C, '<'))
5430159Sbostic 		for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
5530159Sbostic 	else {
5630159Sbostic 		to = C;
5730159Sbostic 		for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
5830159Sbostic 	}
5930159Sbostic 	*C = EOS;
6030159Sbostic 
6130890Sbostic 	if (!(pf = popen(MAIL_CMD, "w")))
6230890Sbostic 		error("sendmail pipe failed.", CHN);
6330159Sbostic 
6430890Sbostic 	fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n", BUGS_HOME, BUGS_HOME, to);
6530159Sbostic 	if (mailhead[SUBJ_TAG].found)
6630890Sbostic 		fprintf(pf, "Subject: Re:%s", mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
6730159Sbostic 	else
6830890Sbostic 		fputs("Subject: Bug report acknowledgement.\n", pf);
6930159Sbostic 	if (mailhead[DATE_TAG].found)
7030890Sbostic 		fprintf(pf, "In-Acknowledgement-Of: Your message of %s", mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
7130159Sbostic 	if (mailhead[MSG_TAG].found)
7230890Sbostic 		fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
7331910Sbostic 	fputs("Precedence: bulk\n\n", pf);	/* vacation(1) uses this... */
7430159Sbostic 	fflush(pf);
7530159Sbostic 
7632654Sbostic 	(void)sprintf(bfr, "%s/%s", dir, ACK_FILE);
7732654Sbostic 	if ((afd = open(bfr, O_RDONLY, 0)) >= 0) {
7830890Sbostic 		while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
7930890Sbostic 			(void)write(fileno(pf), bfr, rval);
8030890Sbostic 		(void)close(afd);
8130159Sbostic 	}
8230159Sbostic 	pclose(pf);
8330159Sbostic }
84