s/nfs/fmtstr/
[mmh] / uip / forw.c
index c3474c5..031c191 100644 (file)
@@ -25,35 +25,25 @@ static struct swit switches[] = {
        { "editor editor", 0 },
 #define NEDITSW  3
        { "noedit", 0 },
-#define FILTSW  4
-       { "filter filterfile", 0 },
-#define FORMSW  5
+#define FORMSW  4
        { "form formfile", 0 },
-#define FRMTSW  6
-       { "format", 5 },
-#define NFRMTSW  7
-       { "noformat", 7 },
-#define MIMESW  8
-       { "mime", 0 },
-#define NMIMESW  9
-       { "nomime", 0 },
-#define DGSTSW  10
+#define DGSTSW  5
        { "digest list", 0 },
-#define ISSUESW  11
+#define ISSUESW  6
        { "issue number", 0 },
-#define VOLUMSW  12
+#define VOLUMSW  7
        { "volume number", 0 },
-#define WHATSW  13
+#define WHATSW  8
        { "whatnowproc program", 0 },
-#define NWHATSW  14
+#define NWHATSW  9
        { "nowhatnowproc", 0 },
-#define VERSIONSW  15
+#define VERSIONSW  10
        { "version", 0 },
-#define HELPSW  16
+#define HELPSW  11
        { "help", 0 },
 
 #ifdef MHE
-#define BILDSW  17
+#define BILDSW  12
        { "build", 5 },  /* interface from mhe */
 #endif /* MHE */
 
@@ -61,20 +51,12 @@ static struct swit switches[] = {
 };
 
 static char drft[BUFSIZ];
-
-static char delim3[] =
-       "\n------------------------------------------------------------\n\n";
-static char delim4[] = "\n------------------------------\n\n";
-
-
-static struct msgs *mp = NULL;  /* used a lot */
+static struct msgs *mp = NULL;
 
 
 /*
 ** static prototypes
 */
-static void mhl_draft(int, char *, int, int, char *, char *);
-static void copy_draft(int, char *, char *, int, int);
 static void add_forw_hdr(char *);
 static int build_form(char *, char *, int, int);
 
@@ -82,15 +64,16 @@ static int build_form(char *, char *, int, int);
 int
 main(int argc, char **argv)
 {
-       int msgp = 0, anot = 0, mime = 0;
+       int msgp = 0, anot = 0;
        int issue = 0, volume = 0;
        int nedit = 0, nwhat = 0, in;
        int out, msgnum;
        char *cp, *cwd, *maildir;
        char *digest = NULL, *ed = NULL;
-       char *filter = NULL, *folder = NULL;
+       char *folder = NULL;
        char *form = NULL, buf[BUFSIZ], value[10];
        char **argp, **arguments, *msgs[MAXARGS];
+       char *fmtstr;
 
 #ifdef MHE
        int buildsw = 0;
@@ -156,39 +139,17 @@ main(int argc, char **argv)
                                nwhat++;
                                continue;
 
-                       case FILTSW:
-                               if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
-                                                       argp[-2]);
-                               filter = getcpy(etcpath(cp));
-                               mime = 0;
-                               continue;
                        case FORMSW:
                                if (!(form = *argp++) || *form == '-')
                                        adios(NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
-                       case FRMTSW:
-                               filter = getcpy(etcpath(mhlforward));
-                               continue;
-                       case NFRMTSW:
-                               filter = NULL;
-                               continue;
-
-                       case MIMESW:
-                               mime++;
-                               filter = NULL;
-                               continue;
-                       case NMIMESW:
-                               mime = 0;
-                               continue;
-
                        case DGSTSW:
                                if (!(digest = *argp++) || *digest == '-')
                                        adios(NULL, "missing argument to %s",
                                                        argp[-2]);
-                               mime = 0;
+                               //mime = 0;
                                continue;
                        case ISSUESW:
                                if (!(cp = *argp++) || *cp == '-')
@@ -253,8 +214,8 @@ main(int argc, char **argv)
                        done(1);
        seq_setprev(mp);  /* set the previous sequence */
 
-       if (filter && access(filter, R_OK) == NOTOK)
-               adios(filter, "unable to read");
+       if ((out = creat(drft, m_gmprot())) == NOTOK)
+               adios(drft, "unable to create");
 
        /* Open form (component) file. */
        if (digest) {
@@ -273,32 +234,17 @@ main(int argc, char **argv)
                if (!form)
                        form = digestcomps;
                in = build_form(form, digest, volume, issue);
-       } else
-               in = open_form(&form, forwcomps);
-
-       if ((out = creat(drft, m_gmprot())) == NOTOK)
-               adios(drft, "unable to create");
-
-       /*
-       ** copy the components into the draft
-       */
-       cpydata(in, out, form, drft);
-       close(in);
-
-       /*
-       ** If filter file is defined, then format the
-       ** messages into the draft using mhlproc.
-       */
-       if (filter) {
-               mhl_draft(out, digest, volume, issue, drft, filter);
-               close(out);
-       } else if (mime) {
-               close(out);
-               add_forw_hdr(drft);
+               cpydata(in, out, form, drft);
+               close(in);
        } else {
-               copy_draft(out, digest, drft, volume, issue);
-               close(out);
+               fmtstr = new_fs(form, forwcomps);
+               if (write(out, fmtstr, strlen(fmtstr)) != strlen(fmtstr)) {
+                       adios(drft, "error writing");
+               }
        }
+       close(out);
+
+       add_forw_hdr(drft);
 
        if (digest) {
                snprintf(buf, sizeof(buf), IFORMAT, digest);
@@ -324,164 +270,6 @@ main(int argc, char **argv)
 
 
 /*
-** 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)
-{
-       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;
-               }
-
-               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.
-*/
-static void
-copy_draft(int out, char *digest, char *file, int volume, int issue)
-{
-       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)
-                       */
-                       cpydgst(fd, out, msgnam, file);
-
-                       close(fd);
-                       msgcnt++;
-               }
-       }
-
-       if (digest) {
-               strncpy(buffer, delim4, sizeof(buffer));
-       } else {
-               snprintf(buffer, sizeof(buffer),
-                               "\n------- End of Forwarded Message%s\n\n",
-                               mp->numsel > 1 ? "s" : "");
-       }
-       write(out, buffer, strlen(buffer));
-
-       if (digest) {
-               snprintf(buffer, sizeof(buffer),
-                               "End of %s Digest [Volume %d Issue %d]\n",
-                               digest, volume, issue);
-               i = strlen(buffer);
-               for (bp = buffer + i; i > 1; i--)
-                       *bp++ = '*';
-               *bp++ = '\n';
-               *bp = 0;
-               write(out, buffer, strlen(buffer));
-       }
-}
-
-
-/*
 ** Create an attachment header for the to be forward messages.
 */
 static void
@@ -509,7 +297,7 @@ build_form(char *form, char *digest, int volume, int issue)
 {
        int in;
        int fmtsize;
-       register char *nfs;
+       register char *fmtstr;
        char *line, tmpfil[BUFSIZ];
        FILE *tmp;
        register struct comp *cptr;
@@ -518,11 +306,11 @@ build_form(char *form, char *digest, int volume, int issue)
        char *cp = NULL;
 
        /* Get new format string */
-       nfs = new_fs(form, NULL, NULL);
-       fmtsize = strlen(nfs) + 256;
+       fmtstr = new_fs(form, NULL);
+       fmtsize = strlen(fmtstr) + 256;
 
        /* Compile format string */
-       fmt_compile(nfs, &fmt);
+       fmt_compile(fmtstr, &fmt);
 
        FINDCOMP(cptr, "digest");
        if (cptr)