- if ((fout = creat(msgname, msg_prot)) < 0) {
- fprintf(stderr, "cannot create %s\n", msgname);
- return;
- }
- while ((n = read(fin, buf, sizeof(buf))) > 0)
- write(fout, buf, n);
- close(fin);
- close(fout);
- }
- unlink(fname);
-}
-
-/*
- * Mail file1 and file2 back to the sender.
- */
-
-reply(to, file1, file2)
- char *to, *file1, *file2;
-{
- int (*istat)(), (*qstat)();
- int pid, w, status, pfd[2], in;
- FILE *fout;
-
- if (debug)
- printf("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%ucbarpa@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, buf, sizeof(buf))) > 0)
- fwrite(buf, 1, w, fout);
- close(in);
- }
- if (file2 && (in = open(file2, 0)) >= 0) {
- while ((w = read(in, buf, sizeof(buf))) > 0)
- fwrite(buf, 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);
-}
-
-/*
- * fix names like "xxx (something)" to "xxx" and
- * "xxx <something>" to "something".
- */
-
-char *
-fixaddr(text)
- char *text;
-{
- register char *cp, *lp, c;
- char *tp;
-
- if (!text)
- return(0);
- for (lp = cp = text; ; ) {
- switch (c = *cp++) {
- case '(':
- while (*cp && *cp++ != ')');
- continue;
- case '<':
- lp = text;
- case '>':
- continue;
- case '\0':
- while (lp != text && (*lp == ' ' || *lp == '\t'))
- lp--;
- *lp = c;
- return(text);
- }
- *lp++ = c;
- }