- if (nwhat)
- done(0);
- what_now(ed, nedit, NOUSE, drft, NULL, 0, mp,
- anot ? "Forwarded" : NULL, inplace, cwd);
- done(1);
- return 1;
-}
-
-
-/*
-** Filter the messages you are forwarding, into the
-** draft calling the mhlproc, and reading its output
-** from a pipe.
-*/
-static void
-mhl_draft(int out, char *digest, int volume, int issue,
- char *file, char *filter, int dashstuff)
-{
- pid_t child_id;
- int i, msgnum, pd[2];
- char *vec[MAXARGS];
- char buf1[BUFSIZ];
- char buf2[BUFSIZ];
-
- if (pipe(pd) == NOTOK)
- adios("pipe", "unable to create");
-
- vec[0] = mhbasename(mhlproc);
-
- for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
- sleep(5);
- switch (child_id) {
- case NOTOK:
- adios("fork", "unable to");
-
- case OK:
- close(pd[0]);
- dup2(pd[1], 1);
- close(pd[1]);
-
- i = 1;
- vec[i++] = "-forwall";
- vec[i++] = "-form";
- vec[i++] = filter;
-
- if (digest) {
- vec[i++] = "-digest";
- vec[i++] = digest;
- vec[i++] = "-issue";
- snprintf(buf1, sizeof(buf1), "%d", issue);
- vec[i++] = buf1;
- vec[i++] = "-volume";
- snprintf(buf2, sizeof(buf2), "%d", volume);
- vec[i++] = buf2;
- }
-
- /*
- ** Are we dashstuffing (quoting) the lines that begin
- ** with `-'. We use the mhl default (don't add any
- ** flag) unless the user has specified a specific flag.
- */
- if (dashstuff > 0)
- vec[i++] = "-dashstuffing";
- else if (dashstuff < 0)
- vec[i++] = "-nodashstuffing";
-
- if (mp->numsel >= MAXARGS - i)
- adios(NULL, "more than %d messages for %s exec",
- MAXARGS - i, vec[0]);
-
- /*
- ** Now add the message names to filter. We can only
- ** handle about 995 messages (because vec is fixed
- ** size), but that should be plenty.
- */
- for (msgnum = mp->lowsel;
- msgnum <= mp->hghsel && i < sizeof(vec) - 1;
- msgnum++)
- if (is_selected(mp, msgnum))
- vec[i++] = getcpy(m_name(msgnum));
- vec[i] = NULL;
-
- execvp(mhlproc, vec);
- fprintf(stderr, "unable to exec ");
- perror(mhlproc);
- _exit(-1);
-
- default:
- close(pd[1]);
- cpydata(pd[0], out, vec[0], file);
- close(pd[0]);
- pidXwait(child_id, mhlproc);
- break;
- }
-}
-
-
-/*
-** Copy the messages into the draft. The messages are
-** not filtered through the mhlproc. Do dashstuffing if
-** necessary.
-*/
-static void
-copy_draft(int out, char *digest, char *file, int volume, int issue,
- int dashstuff)
-{
- int fd,i, msgcnt, msgnum;
- int len, buflen;
- register char *bp, *msgnam;
- char buffer[BUFSIZ];
-
- msgcnt = 1;
- for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
- if (is_selected(mp, msgnum)) {
- if (digest) {
- strncpy(buffer, msgnum == mp->lowsel ?
- delim3 : delim4, sizeof(buffer));
- } else {
- /* Get buffer ready to go */
- bp = buffer;
- buflen = sizeof(buffer);
-
- strncpy(bp, "\n-------", buflen);
- len = strlen(bp);
- bp += len;
- buflen -= len;
-
- if (msgnum == mp->lowsel) {
- snprintf(bp, buflen, " Forwarded Message%s", mp->numsel > 1 ? "s" : "");
- } else {
- snprintf(bp, buflen, " Message %d", msgcnt);
- }
- len = strlen(bp);
- bp += len;
- buflen -= len;
-
- strncpy(bp, "\n\n", buflen);
- }
- write(out, buffer, strlen(buffer));
-
- if ((fd = open(msgnam = m_name (msgnum), O_RDONLY))
- == NOTOK) {
- admonish(msgnam, "unable to read message");
- continue;
- }
-
- /*
- ** Copy the message. Add RFC934 quoting (dashstuffing)
- ** unless given the -nodashstuffing flag.
- */
- if (dashstuff >= 0)
- cpydgst(fd, out, msgnam, file);
- else
- cpydata(fd, out, msgnam, file);
-
- close(fd);
- msgcnt++;
- }
- }