]> diplodocus.org Git - nmh/blobdiff - uip/rcvstore.c
Reworked attach to add charset to Content-Type string for
[nmh] / uip / rcvstore.c
index acf54beb237bc8e779e00f258bbf711516942463..2822093e57f851e1b207f82de24512f7effa0093 100644 (file)
 #include <h/mh.h>
 #include <fcntl.h>
 #include <h/signals.h>
-#include <errno.h>
-#include <signal.h>
 #include <h/mts.h>
 
-static struct swit switches[] = {
-#define CRETSW         0
-    { "create",        0 },
-#define NCRETSW        1
-    { "nocreate", 0 },
-#define UNSEENSW       2
-    { "unseen", 0 },
-#define NUNSEENSW      3
-    { "nounseen", 0 },
-#define PUBSW          4
-    { "public",        0 },
-#define NPUBSW         5
-    { "nopublic",  0 },
-#define ZEROSW         6
-    { "zero",  0 },
-#define NZEROSW        7
-    { "nozero",        0 },
-#define SEQSW          8
-    { "sequence name", 0 },
-#define VERSIONSW      9
-    { "version", 0 },
-#define HELPSW        10
-    { "help", 0 },
-    { NULL, 0 }
-};
+#define RCVSTORE_SWITCHES \
+    X("create", 0, CRETSW) \
+    X("nocreate", 0, NCRETSW) \
+    X("unseen", 0, UNSEENSW) \
+    X("nounseen", 0, NUNSEENSW) \
+    X("public", 0, PUBSW) \
+    X("nopublic", 0, NPUBSW) \
+    X("zero", 0, ZEROSW) \
+    X("nozero", 0, NZEROSW) \
+    X("sequence name", 0, SEQSW) \
+    X("version", 0, VERSIONSW) \
+    X("help", 0, HELPSW) \
+
+#define X(sw, minchars, id) id,
+DEFINE_SWITCH_ENUM(RCVSTORE);
+#undef X
+
+#define X(sw, minchars, id) { sw, minchars, id },
+DEFINE_SWITCH_ARRAY(RCVSTORE, switches);
+#undef X
 
 
 /*
@@ -56,7 +49,8 @@ main (int argc, char **argv)
     int fd, msgnum;
     size_t seqp = 0;
     char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
-    char **argp, **arguments, *seqs[NUMATTRS+1];
+    char **argp, **arguments;
+    svector_t seqs = svector_create (0);
     struct msgs *mp;
     struct stat st;
 
@@ -97,10 +91,8 @@ main (int argc, char **argv)
                if (!(cp = *argp++) || *cp == '-')
                    adios (NULL, "missing argument name to %s", argp[-2]);
 
-               /* check if too many sequences specified */
-               if (seqp >= NUMATTRS)
-                   adios (NULL, "too many sequences (more than %d) specified", NUMATTRS);
-               seqs[seqp++] = cp;
+               svector_push_back (seqs, cp);
+               seqp++;
                continue;
 
            case UNSEENSW:
@@ -142,8 +134,6 @@ main (int argc, char **argv)
        }
     }
 
-    seqs[seqp] = NULL; /* NULL terminate list of sequences */
-
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
@@ -198,7 +188,7 @@ main (int argc, char **argv)
     /*
      * read folder and create message structure
      */
-    if (!(mp = folder_read (folder)))
+    if (!(mp = folder_read (folder, 1)))
        adios (NULL, "unable to read folder %s", folder);
 
     /*
@@ -212,11 +202,17 @@ main (int argc, char **argv)
      * Add the message to any extra sequences
      * that have been specified.
      */
-    for (seqp = 0; seqs[seqp]; seqp++) {
-       if (!seq_addmsg (mp, seqs[seqp], msgnum, publicsw, zerosw))
-           done (1);
+    if (seqp) {
+       /* The only reason that seqp was checked to be non-zero is in
+          case a -nosequence switch is added. */
+       for (seqp = 0; seqp < svector_size (seqs); seqp++) {
+           if (!seq_addmsg (mp, svector_at (seqs, seqp), msgnum, publicsw,
+                            zerosw))
+               done (1);
+       }
     }
 
+    svector_free (seqs);
     seq_setunseen (mp, 0);     /* synchronize any Unseen-Sequence's      */
     seq_save (mp);             /* synchronize and save message sequences */
     folder_free (mp);          /* free folder/message structure          */