Changed msg_style and msg_delim to be file static to m_getfld.c
[mmh] / uip / dist.c
index 4b6ce69..b7799be 100644 (file)
@@ -2,14 +2,13 @@
 /*
  * dist.c -- re-distribute a message
  *
- * $Id$
- *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
 #include <h/mh.h>
+#include <h/utils.h>
 #include <fcntl.h>
 
 static struct swit switches[] = {
@@ -43,6 +42,20 @@ static struct swit switches[] = {
     { "help", 0 },
 #define        FILESW  14
     { "file file", -4 },       /* interface from msh */
+#define FROMSW  15
+    { "from address", 0 },
+#define TOSW    16
+    { "to address", 0 },
+#define CCSW    17
+    { "cc address", 0 },
+#define FCCSW   18
+    { "fcc mailbox", 0 },
+#define WIDTHSW 19
+    { "width columns", 0 },
+#define ATFILESW 20
+    { "atfile", 0 },
+#define NOATFILESW 21
+    { "noatfile", 0 },
     { NULL, 0 }
 };
 
@@ -75,9 +88,12 @@ main (int argc, char **argv)
 {
     int anot = 0, inplace = 1, nedit = 0;
     int nwhat = 0, i, in, isdf = 0, out;
+    int outputlinelen = OUTPUTLINELEN;
+    int dat[5], atfile = 0;
     char *cp, *cwd, *maildir, *msgnam, *dfolder = NULL;
     char *dmsg = NULL, *ed = NULL, *file = NULL, *folder = NULL;
     char *form = NULL, *msg = NULL, buf[BUFSIZ], drft[BUFSIZ];
+    char *from = NULL, *to = NULL, *cc = NULL, *fcc = NULL;
     char **argp, **arguments;
     struct msgs *mp = NULL;
     struct stat st;
@@ -106,10 +122,10 @@ main (int argc, char **argv)
                    snprintf (buf, sizeof(buf), "%s [+folder] [msg] [switches]",
                        invo_name);
                    print_help (buf, switches, 1);
-                   done (1);
+                   done (0);
                case VERSIONSW:
                    print_version(invo_name);
-                   done (1);
+                   done (0);
 
                case ANNOSW: 
                    anot++;
@@ -173,13 +189,48 @@ main (int argc, char **argv)
                    dfolder = NULL;
                    isdf = NOTOK;
                    continue;
+
+               case FROMSW:
+                   if (!(cp = *argp++) || *cp == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+                   from = addlist(from, cp);
+                   continue;
+               case TOSW:
+                   if (!(cp = *argp++) || *cp == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+                   to = addlist(to, cp);
+                   continue;
+               case CCSW:
+                   if (!(cp = *argp++) || *cp == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+                   cc = addlist(cc, cp);
+                   continue;
+               case FCCSW:
+                   if (!(cp = *argp++) || *cp == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+                   fcc = addlist(fcc, cp);
+                   continue;
+
+               case WIDTHSW:
+                   if (!(cp = *argp++) || *cp == '-')
+                       adios (NULL, "missing argument to %s", argp[-2]);
+                   if ((outputlinelen = atoi(cp)) < 10)
+                       adios (NULL, "impossible width %d", outputlinelen);
+                   continue;
+
+               case ATFILESW:
+                   atfile++;
+                   continue;
+               case NOATFILESW:
+                   atfile = 0;
+                   continue;
            }
        }
        if (*cp == '+' || *cp == '@') {
            if (folder)
                adios (NULL, "only one folder at a time!");
            else
-               folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
+               folder = pluspath (cp);
        } else {
            if (msg)
                adios (NULL, "only one message at a time!");
@@ -195,15 +246,6 @@ main (int argc, char **argv)
     if (file && (msg || folder))
        adios (NULL, "can't mix files and folders/msgs");
 
-    if (form) {
-       if ((in = open (etcpath (form), O_RDONLY)) == NOTOK)
-           adios (form, "unable to open form file");
-    } else {
-       if ((in = open (etcpath (distcomps), O_RDONLY)) == NOTOK)
-           adios (distcomps, "unable to open default components file");
-       form = distcomps;
-    }
-
 try_it_again:
     strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft));
 
@@ -234,12 +276,6 @@ try_it_again:
            }
        }
     }
-    if ((out = creat (drft, m_gmprot ())) == NOTOK)
-       adios (drft, "unable to create");
-
-    cpydata (in, out, form, drft);
-    close (in);
-    close (out);
 
     if (file) {
        /*
@@ -277,6 +313,25 @@ try_it_again:
     }
 
     msgnam = file ? file : getcpy (m_name (mp->lowsel));
+
+    dat[0] = mp ? mp->lowsel : 0;
+    dat[1] = 0;
+    dat[2] = 0;
+    dat[3] = outputlinelen;
+    dat[4] = 0;
+
+    if (!form)
+       form = distcomps;
+
+    in = build_form(form, NULL, dat, from, to, cc, fcc, NULL, msgnam);
+
+    if ((out = creat (drft, m_gmprot ())) == NOTOK)
+       adios (drft, "unable to create");
+
+    cpydata (in, out, form, drft);
+    close (in);
+    close (out);
+
     if ((in = open (msgnam, O_RDONLY)) == NOTOK)
        adios (msgnam, "unable to open message");
 
@@ -289,7 +344,8 @@ try_it_again:
 
     if (nwhat)
        done (0);
-    what_now (ed, nedit, NOUSE, drft, msgnam, 1, mp,
-       anot ? "Resent" : NULL, inplace, cwd);
-    return done (1);
+    what_now (ed, nedit, NOUSE, drft, msgnam, 1, mp, anot ? "Resent" : NULL,
+           inplace, cwd, atfile);
+    done (1);
+    return 1;
 }