xref: /csrg-svn/libexec/bugfiler/reply.c (revision 30159)
1*30159Sbostic /*
2*30159Sbostic  * Copyright (c) 1986 Regents of the University of California.
3*30159Sbostic  * All rights reserved.  The Berkeley software License Agreement
4*30159Sbostic  * specifies the terms and conditions for redistribution.
5*30159Sbostic  */
6*30159Sbostic 
7*30159Sbostic #ifndef lint
8*30159Sbostic static char sccsid[] = "@(#)reply.c	5.1 (Berkeley) 86/11/25";
9*30159Sbostic #endif not lint
10*30159Sbostic 
11*30159Sbostic #include <bug.h>
12*30159Sbostic #include <sys/file.h>
13*30159Sbostic #include <stdio.h>
14*30159Sbostic 
15*30159Sbostic extern HEADER	mailhead[];			/* mail headers */
16*30159Sbostic 
17*30159Sbostic /*
18*30159Sbostic  * reply --
19*30159Sbostic  *	tell the user we got their bug report
20*30159Sbostic  */
21*30159Sbostic reply()
22*30159Sbostic {
23*30159Sbostic 	register char	*C,			/* traveling pointer */
24*30159Sbostic 			*to;			/* who we're replying to */
25*30159Sbostic 	register int	afd,			/* ack file descriptor */
26*30159Sbostic 			rval;			/* return value */
27*30159Sbostic 	FILE	*pf,				/* pipe pointer */
28*30159Sbostic 		*popen();
29*30159Sbostic 	char	*mktemp(), *strcpy(), *index();
30*30159Sbostic 
31*30159Sbostic 	if (mailhead[RPLY_TAG].found) {
32*30159Sbostic 		for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
33*30159Sbostic 		if (*C)
34*30159Sbostic 			goto gotone;
35*30159Sbostic 	}
36*30159Sbostic 	if (mailhead[FROM_TAG].found) {
37*30159Sbostic 		for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
38*30159Sbostic 		if (*C)
39*30159Sbostic 			goto gotone;
40*30159Sbostic 	}
41*30159Sbostic 	if (mailhead[CFROM_TAG].found) {
42*30159Sbostic 		for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
43*30159Sbostic 		if (*C)
44*30159Sbostic 			goto gotone;
45*30159Sbostic 	}
46*30159Sbostic 	return;
47*30159Sbostic 
48*30159Sbostic 	/* if it's a foo <XXX>, get the XXX, else get foo (first string) */
49*30159Sbostic gotone:	if (to = index(C,'<'))
50*30159Sbostic 		for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
51*30159Sbostic 	else {
52*30159Sbostic 		to = C;
53*30159Sbostic 		for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
54*30159Sbostic 	}
55*30159Sbostic 	*C = EOS;
56*30159Sbostic 
57*30159Sbostic 	if (!(pf = popen(MAIL_CMD,"w")))
58*30159Sbostic 		error("sendmail pipe failed.",CHN);
59*30159Sbostic 
60*30159Sbostic 	fprintf(pf,"Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n",BUGS_HOME,BUGS_HOME,to);
61*30159Sbostic 	if (mailhead[SUBJ_TAG].found)
62*30159Sbostic 		fprintf(pf,"Subject: Re:%s",mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
63*30159Sbostic 	else
64*30159Sbostic 		fputs("Subject: Bug report acknowledgement.\n",pf);
65*30159Sbostic 	if (mailhead[DATE_TAG].found)
66*30159Sbostic 		fprintf(pf,"In-Acknowledgement-Of: Your message of %s",mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
67*30159Sbostic 	if (mailhead[MSG_TAG].found)
68*30159Sbostic 		fprintf(pf,"\t\t%s",mailhead[MSG_TAG].line);
69*30159Sbostic 	putc('\n',pf);
70*30159Sbostic 	fflush(pf);
71*30159Sbostic 
72*30159Sbostic 	if ((afd = open(ACK_FILE,O_RDONLY,0)) >= 0) {
73*30159Sbostic 		while ((rval = read(afd,bfr,sizeof(bfr))) != ERR && rval)
74*30159Sbostic 			write(fileno(pf),bfr,rval);
75*30159Sbostic 		close(afd);
76*30159Sbostic 	}
77*30159Sbostic 
78*30159Sbostic 	pclose(pf);
79*30159Sbostic }
80