- 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);
-}
-
-/*
- * Redistribute a bug report to those people indicated
- * in the redistribution list file. Perhaps should also
- * annotate bug report with this information for future
- * reference?
- */
-redistribute(folder, num)
- char *folder;
- int num;
-{
- FILE *fredist, *fbug, *ftemp;
- char line[BUFSIZ], bug[2 * MAXNAMLEN + 1];
- register char *cp;
- int redistcnt, continuation, first;
-
- fredist = fopen(redistfile, "r");
- if (fredist == NULL) {
- if (debug)
- printf("redistribute(%s, %d), no distribution list\n",
- folder, num);
- return;
- }
- continuation = 0;
- first = 1;
- redistcnt = 0;
- while (fgets(line, sizeof (line) - 1, fredist) != NULL) {
- if (debug)
- printf("%s: %s", redistfile, line);
- if (continuation && index(line, '\\'))
- continue;
- continuation = 0;
- cp = any(line, " \t");
- if (cp == NULL)
- continue;
- *cp++ = '\0';
- if (strcmp(folder, line) == 0)
- goto found;
- if (index(cp, '\\'))
- continuation = 1;
- }
- if (debug)
- printf("no redistribution list found\n");
- fclose(fredist);
- return;
-found:
- mktemp(disttmp);
- ftemp = fopen(disttmp, "w+r");
- if (ftemp == NULL) {
- if (debug)
- printf("%s: couldn't create\n", disttmp);
- return;
- }
-again:
- if (debug)
- printf("redistribution list %s", cp);
- while (cp) {
- char *user, terminator;
-
- while (*cp && (*cp == ' ' || *cp == '\t' || *cp == ','))
- cp++;
- user = cp, cp = any(cp, ", \t\n\\");
- if (cp) {
- terminator = *cp;
- *cp++ = '\0';
- if (terminator == '\n')
- cp = 0;
- if (terminator == '\\')
- continuation++;
- }
- if (*user == '\0')
- continue;
- if (debug)
- printf("copy to %s\n", user);
- if (first) {
- fprintf(ftemp, "To: %s", user);
- first = 0;
- } else
- fprintf(ftemp, ", %s", user);
- redistcnt++;
- }
- if (!first)
- putc('\n', ftemp);
- if (continuation) {
- first = 1;
- continuation = 0;
- cp = line;
- if (fgets(line, sizeof (line) - 1, fredist))
- goto again;
- }
- fclose(fredist);
- if (redistcnt == 0)
- goto cleanup;
- fprintf(ftemp, "Subject: ");
- if (SUBJECT_I)
- fprintf(ftemp, "%s\n", SUBJECT_I);
- else
- fprintf(ftemp, "Untitled bug report\n");
- fprintf(ftemp, "\nRedistributed-by: %s%s\n", BUGS_NAME, BUGS_HOME);
- /*
- * Create copy of bug report. Perhaps we should
- * truncate large messages and just give people
- * a pointer to the original?
- */
- sprintf(bug, "%s/%d", folder, num);
- fbug = fopen(bug, "r");
- if (fbug == NULL) {
- if (debug)
- printf("%s: disappeared?\n", bug);
- goto cleanup;
- }
- first = 1;
- while (fgets(line, sizeof (line) - 1, fbug)) {
- /* first blank line indicates start of mesg */
- if (first && line[0] == '\n') {
- first = 0;
- continue;
- }
- fputs(line, ftemp);
- }
- fclose(fbug);
- if (first) {
- if (debug)
- printf("empty bug report?\n");
- goto cleanup;
- }
- if (dodeliver(ftemp))
- unlink(disttmp);
- fclose(ftemp);
- return;
-cleanup:
- fclose(ftemp);
- unlink(disttmp);
-}
-
-dodeliver(fd)
- FILE *fd;
-{
- char buf[BUFSIZ], cmd[BUFSIZ];
- FILE *pf, *popen();
-
- strcpy(cmd, MAILCMD);
- if (debug) {
- strcat(cmd, " -v");
- printf("dodeliver \"%s\"\n", cmd);
- }
- pf = popen(cmd, "w");
- if (pf == NULL) {
- if (debug)
- printf("dodeliver, \"%s\" failed\n", cmd);
- return (0);
- }
- rewind(fd);
- while (fgets(buf, sizeof (buf) - 1, fd)) {
- if (debug)
- printf("%s", buf);
- (void) fputs(buf, pf);
- }
- if (debug)
- printf("EOF\n");
- (void) pclose(pf);
- return (1);
-}
-
-/*
- * Mail file1 and file2 back to the sender.
- */
-
-reply(to, file1, file2)
- char *to, *file1, *file2;
-{
- int pfd[2], in, w;
- 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+r")) == NULL) {
- fprintf(stderr, "Can't create %s\n", draft);
- return;
- }
- /*
- * Output the proper header information.
- */
- fprintf(fout, "Reply-To: %s%s\n", BUGS_NAME, BUGS_HOME);
- fprintf(fout, "From: %s%s (Bugs Bunny)\n", BUGS_NAME, BUGS_HOME);
- 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);
- }
- if (dodeliver(fout))
- unlink(draft);
- fclose(fout);