date and time created 88/06/29 21:19:25 by bostic
[unix-history] / usr / src / libexec / bugfiler / reply.c
CommitLineData
85ca7091 1/*
aec2eff2
KB
2 * Copyright (c) 1986, 1987 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
85ca7091
KB
11 */
12
13#ifndef lint
aec2eff2
KB
14static char sccsid[] = "@(#)reply.c 5.5 (Berkeley) %G%";
15#endif /* not lint */
85ca7091
KB
16
17#include <bug.h>
18#include <sys/file.h>
19#include <stdio.h>
20
85ca7091
KB
21/*
22 * reply --
d8336336 23 * tell the user we got their silly little bug report
85ca7091
KB
24 */
25reply()
26{
27 register char *C, /* traveling pointer */
28 *to; /* who we're replying to */
29 register int afd, /* ack file descriptor */
30 rval; /* return value */
31 FILE *pf, /* pipe pointer */
32 *popen();
d8336336 33 char *index();
85ca7091
KB
34
35 if (mailhead[RPLY_TAG].found) {
36 for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
37 if (*C)
38 goto gotone;
39 }
40 if (mailhead[FROM_TAG].found) {
41 for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
42 if (*C)
43 goto gotone;
44 }
45 if (mailhead[CFROM_TAG].found) {
46 for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
47 if (*C)
48 goto gotone;
49 }
50 return;
51
52 /* if it's a foo <XXX>, get the XXX, else get foo (first string) */
d8336336 53gotone: if (to = index(C, '<'))
85ca7091
KB
54 for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
55 else {
56 to = C;
57 for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
58 }
59 *C = EOS;
60
d8336336
KB
61 if (!(pf = popen(MAIL_CMD, "w")))
62 error("sendmail pipe failed.", CHN);
85ca7091 63
d8336336 64 fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n", BUGS_HOME, BUGS_HOME, to);
85ca7091 65 if (mailhead[SUBJ_TAG].found)
d8336336 66 fprintf(pf, "Subject: Re:%s", mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
85ca7091 67 else
d8336336 68 fputs("Subject: Bug report acknowledgement.\n", pf);
85ca7091 69 if (mailhead[DATE_TAG].found)
d8336336 70 fprintf(pf, "In-Acknowledgement-Of: Your message of %s", mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
85ca7091 71 if (mailhead[MSG_TAG].found)
d8336336 72 fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
3fa5a997 73 fputs("Precedence: bulk\n\n", pf); /* vacation(1) uses this... */
85ca7091
KB
74 fflush(pf);
75
9377830c
KB
76 (void)sprintf(bfr, "%s/%s", dir, ACK_FILE);
77 if ((afd = open(bfr, O_RDONLY, 0)) >= 0) {
d8336336
KB
78 while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
79 (void)write(fileno(pf), bfr, rval);
80 (void)close(afd);
85ca7091 81 }
85ca7091
KB
82 pclose(pf);
83}