BSD 4_3_Tahoe release
[unix-history] / usr / src / ucb / sendbug / 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
5e8b0e60
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
85ca7091
KB
16 */
17
18#ifndef lint
ca67e7b4 19static char sccsid[] = "@(#)reply.c 5.6 (Berkeley) 6/29/88";
aec2eff2 20#endif /* not lint */
85ca7091
KB
21
22#include <bug.h>
23#include <sys/file.h>
24#include <stdio.h>
25
85ca7091
KB
26/*
27 * reply --
d8336336 28 * tell the user we got their silly little bug report
85ca7091
KB
29 */
30reply()
31{
32 register char *C, /* traveling pointer */
33 *to; /* who we're replying to */
34 register int afd, /* ack file descriptor */
35 rval; /* return value */
36 FILE *pf, /* pipe pointer */
37 *popen();
d8336336 38 char *index();
85ca7091
KB
39
40 if (mailhead[RPLY_TAG].found) {
41 for (C = mailhead[RPLY_TAG].line + mailhead[RPLY_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
42 if (*C)
43 goto gotone;
44 }
45 if (mailhead[FROM_TAG].found) {
46 for (C = mailhead[FROM_TAG].line + mailhead[FROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
47 if (*C)
48 goto gotone;
49 }
50 if (mailhead[CFROM_TAG].found) {
51 for (C = mailhead[CFROM_TAG].line + mailhead[CFROM_TAG].len;*C != '\n' && (*C == ' ' || *C == '\t');++C);
52 if (*C)
53 goto gotone;
54 }
55 return;
56
57 /* if it's a foo <XXX>, get the XXX, else get foo (first string) */
d8336336 58gotone: if (to = index(C, '<'))
85ca7091
KB
59 for (C = ++to;*C != '\n' && *C != ' ' && *C != '\t' && *C != '>';++C);
60 else {
61 to = C;
62 for (to = C++;*C != '\n' && *C != ' ' && *C != '\t';++C);
63 }
64 *C = EOS;
65
d8336336
KB
66 if (!(pf = popen(MAIL_CMD, "w")))
67 error("sendmail pipe failed.", CHN);
85ca7091 68
d8336336 69 fprintf(pf, "Reply-To: %s\nFrom: %s (Bugs Bunny)\nTo: %s\n", BUGS_HOME, BUGS_HOME, to);
85ca7091 70 if (mailhead[SUBJ_TAG].found)
d8336336 71 fprintf(pf, "Subject: Re:%s", mailhead[SUBJ_TAG].line + mailhead[SUBJ_TAG].len);
85ca7091 72 else
d8336336 73 fputs("Subject: Bug report acknowledgement.\n", pf);
85ca7091 74 if (mailhead[DATE_TAG].found)
d8336336 75 fprintf(pf, "In-Acknowledgement-Of: Your message of %s", mailhead[DATE_TAG].line + mailhead[DATE_TAG].len);
85ca7091 76 if (mailhead[MSG_TAG].found)
d8336336 77 fprintf(pf, "\t\t%s", mailhead[MSG_TAG].line);
3fa5a997 78 fputs("Precedence: bulk\n\n", pf); /* vacation(1) uses this... */
85ca7091
KB
79 fflush(pf);
80
9377830c
KB
81 (void)sprintf(bfr, "%s/%s", dir, ACK_FILE);
82 if ((afd = open(bfr, O_RDONLY, 0)) >= 0) {
d8336336
KB
83 while ((rval = read(afd, bfr, sizeof(bfr))) != ERR && rval)
84 (void)write(fileno(pf), bfr, rval);
85 (void)close(afd);
85ca7091 86 }
85ca7091
KB
87 pclose(pf);
88}