Removed the -fcc switch from repl(1).
[mmh] / uip / replsbr.c
index 1bdab9e..852becd 100644 (file)
@@ -66,8 +66,8 @@ static void replfilter(FILE *, FILE *, char *);
 
 
 void
-replout(FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
-       int mime, char *form, char *filter, char *fcc)
+replout(FILE *inb, char *msg, char *drft, struct msgs *mp,
+       int mime, char *form, char *filter)
 {
        register int state, i;
        register struct comp *cptr;
@@ -127,12 +127,6 @@ replout(FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
                if (cptr)
                        cptr->c_name = "";
        }
-       /* set up the "fcc" pseudo-component */
-       if (fcc) {
-               FINDCOMP(cptr, "fcc");
-               if (cptr)
-                       cptr->c_text = getcpy(fcc);
-       }
        if ((cp = getenv("USER"))) {
                FINDCOMP(cptr, "user");
                if (cptr)
@@ -147,60 +141,60 @@ replout(FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
        for (state = FLD;;) {
                state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb);
                switch (state) {
-                       case FLD:
-                       case FLDPLUS:
-                               /*
-                               ** if we're interested in this component,
-                               ** save a pointer to the component text,
-                               ** then start using our next free buffer
-                               ** as the component temp buffer (buffer
-                               ** switching saves an extra copy of the
-                               ** component text).
-                               */
-                               if ((cptr = wantcomp[CHASH(name)]))
-                                       do {
-                                               if (!mh_strcasecmp(name, cptr->c_name)) {
-                                                       char_read += msg_count;
-                                                       if (! cptr->c_text) {
-                                                               i = strlen(cptr->c_text = tmpbuf) - 1;
-                                                               if (tmpbuf[i] == '\n')
-                                                                       tmpbuf[i] = '\0';
-                                                               *--savecomp = cptr;
-                                                               tmpbuf = *nxtbuf++;
-                                                       } else {
-                                                               i = strlen(cp = cptr->c_text) - 1;
-                                                               if (cp[i] == '\n') {
-                                                                       if (cptr->c_type & CT_ADDR) {
-                                                                               cp[i] = '\0';
-                                                                               cp = add(",\n\t", cp);
-                                                                       } else {
-                                                                               cp = add("\t", cp);
-                                                                       }
+               case FLD:
+               case FLDPLUS:
+                       /*
+                       ** if we're interested in this component, save
+                       ** a pointer to the component text, then start
+                       ** using our next free buffer as the component
+                       ** temp buffer (buffer switching saves an extra
+                       ** copy of the component text).
+                       */
+                       if ((cptr = wantcomp[CHASH(name)]))
+                               do {
+                                       if (!mh_strcasecmp(name, cptr->c_name)) {
+                                               char_read += msg_count;
+                                               if (! cptr->c_text) {
+                                                       i = strlen(cptr->c_text = tmpbuf) - 1;
+                                                       if (tmpbuf[i] == '\n')
+                                                               tmpbuf[i] = '\0';
+                                                       *--savecomp = cptr;
+                                                       tmpbuf = *nxtbuf++;
+                                               } else {
+                                                       i = strlen(cp = cptr->c_text) - 1;
+                                                       if (cp[i] == '\n') {
+                                                               if (cptr->c_type & CT_ADDR) {
+                                                                       cp[i] = '\0';
+                                                                       cp = add(",\n\t", cp);
+                                                               } else {
+                                                                       cp = add("\t", cp);
                                                                }
-                                                               cptr->c_text = add(tmpbuf, cp);
                                                        }
-                                                       while (state == FLDPLUS) {
-                                                               state = m_getfld(state, name, tmpbuf,
-                                                                                                 SBUFSIZ, inb);
-                                                               cptr->c_text = add(tmpbuf, cptr->c_text);
-                                                               char_read += msg_count;
-                                                       }
-                                                       break;
+                                                       cptr->c_text = add(tmpbuf, cp);
+                                               }
+                                               while (state == FLDPLUS) {
+                                                       state = m_getfld(state, name, tmpbuf,
+                                                                                         SBUFSIZ, inb);
+                                                       cptr->c_text = add(tmpbuf, cptr->c_text);
+                                                       char_read += msg_count;
                                                }
-                                       } while ((cptr = cptr->c_next));
+                                               break;
+                                       }
+                               } while ((cptr = cptr->c_next));
 
-                               while (state == FLDPLUS)
-                                       state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb);
-                               break;
+                       while (state == FLDPLUS)
+                               state = m_getfld(state, name, tmpbuf,
+                                               SBUFSIZ, inb);
+                       break;
 
-                       case LENERR:
-                       case FMTERR:
-                       case BODY:
-                       case FILEEOF:
-                               goto finished;
+               case LENERR:
+               case FMTERR:
+               case BODY:
+               case FILEEOF:
+                       goto finished;
 
-                       default:
-                               adios(NULL, "m_getfld() returned %d", state);
+               default:
+                       adios(NULL, "m_getfld() returned %d", state);
                }
        }
 
@@ -236,7 +230,7 @@ finished:
        dat[0] = 0;
        dat[1] = 0;
        dat[2] = 0;
-       dat[3] = outputlinelen;
+       dat[3] = OUTPUTLINELEN;
        dat[4] = 0;
        fmt_scan(fmt, scanl, i, dat);
        fputs(scanl, out);
@@ -245,19 +239,13 @@ finished:
                fputs( badaddrs, out);
        }
 
-       /*
-       ** Check if we should filter the message
-       ** or add mhbuild directives
-       */
+       /* Check if we should filter the message */
        if (filter) {
                fflush(out);
                if (ferror(out))
                        adios(drft, "error writing");
 
                replfilter(inb, out, filter);
-       } else if (mime && mp) {
-               fprintf(out, "#forw [original message] +%s %s\n",
-                               mp->foldpath, m_name(mp->lowsel));
        }
 
        fflush(out);
@@ -265,6 +253,15 @@ finished:
                adios(drft, "error writing");
        fclose(out);
 
+       /* if we want mime, then add an attachment header */
+       if (!filter && mime && mp) {
+               char buffer[BUFSIZ];
+
+               snprintf(buffer, sizeof buffer, "+%s %s",
+                               mp->foldpath, m_name(mp->lowsel));
+               annotate(drft, attach_hdr, buffer, 0, -2, 1);
+       }
+
        /* return dynamically allocated buffers */
        free(scanl);
        for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++);
@@ -441,29 +438,28 @@ replfilter(FILE *in, FILE *out, char *filter)
        rewind(in);
        lseek(fileno(in), (off_t) 0, SEEK_SET);
 
-       switch (pid = vfork()) {
-               case NOTOK:
-                       adios("fork", "unable to");
-
-               case OK:
-                       dup2(fileno(in), fileno(stdin));
-                       dup2(fileno(out), fileno(stdout));
-                       closefds(3);
-
-                       execlp(mhlproc, mhl, "-form", filter, "-noclear",
-                                       NULL);
-                       errstr = strerror(errno);
-                       write(2, "unable to exec ", 15);
-                       write(2, mhlproc, strlen(mhlproc));
-                       write(2, ": ", 2);
-                       write(2, errstr, strlen(errstr));
-                       write(2, "\n", 1);
-                       _exit(-1);
-
-               default:
-                       if (pidXwait(pid, mhl))
-                               done(1);
-                       fseek(out, 0L, SEEK_END);
-                       break;
+       switch (pid = fork()) {
+       case NOTOK:
+               adios("fork", "unable to");
+
+       case OK:
+               dup2(fileno(in), fileno(stdin));
+               dup2(fileno(out), fileno(stdout));
+               closefds(3);
+
+               execlp(mhlproc, mhl, "-form", filter, "-noclear", NULL);
+               errstr = strerror(errno);
+               write(2, "unable to exec ", 15);
+               write(2, mhlproc, strlen(mhlproc));
+               write(2, ": ", 2);
+               write(2, errstr, strlen(errstr));
+               write(2, "\n", 1);
+               _exit(-1);
+
+       default:
+               if (pidXwait(pid, mhl))
+                       done(1);
+               fseek(out, 0L, SEEK_END);
+               break;
        }
 }