- if (debug)
- fprintf(stderr, "reply(%s, %s, %s)\n", to, file1, file2);
- /*
- * Create a temporary file to put the message in.
- */
- mktemp(draft);
- if ((fout = fopen(draft, "w")) == NULL) {
- fprintf(stderr, "Can't create %s\n", draft);
- return;
- }
- /*
- * Output the proper header information.
- */
- fprintf(fout, "Reply-To: 4bsd-bugs@BERKELEY\n");
- if (RETURNPATH_I != NULL)
- to = RETURNPATH_I;
- if (REPLYTO_I != NULL)
- to = REPLYTO_I;
- if ((to = fixaddr(to)) == 0) {
- fprintf(stderr, "No one to reply to\n");
- return;
- }
- fprintf(fout, "To: %s\n", to);
- if (SUBJECT_I) {
- fprintf(fout, "Subject: ");
- if ((SUBJECT_I[0] != 'R' && SUBJECT_I[0] != 'r') ||
- (SUBJECT_I[1] != 'E' && SUBJECT_I[1] != 'e') ||
- SUBJECT_I[2] != ':')
- fprintf(fout, "Re: ");
- fprintf(fout, "%s\n", SUBJECT_I);
- }
- if (DATE_I) {
- fprintf(fout, "In-Acknowledgement-Of: Your message of ");
- fprintf(fout, "%s.\n", DATE_I);
- if (MSGID_I)
- fprintf(fout, " %s\n", MSGID_I);
- }
- fprintf(fout, "----------\n");
- if ((in = open(file1, 0)) >= 0) {
- while ((w = read(in, line, sizeof(line))) > 0)
- fwrite(line, 1, w, fout);
- close(in);
- }
- if (file2 && (in = open(file2, 0)) >= 0) {
- while ((w = read(in, line, sizeof(line))) > 0)
- fwrite(line, 1, w, fout);
- close(in);
- }
- fclose(fout);
- while ((pid = fork()) == -1)
- sleep(5);
- if (pid == 0) {
- execl(deliver, "deliver", draft, 0);
- _exit(127);
- }
- istat = signal(SIGINT, SIG_IGN);
- qstat = signal(SIGQUIT, SIG_IGN);
- while ((w = wait(&status)) != -1 && w != pid);
- signal(SIGINT, istat);
- signal(SIGQUIT, qstat);
- if (w != -1 && status == 0)
- unlink(draft);