allow msgs as parameters for whom
[mmh] / uip / whom.c
index 7486dd8..e664f4b 100644 (file)
@@ -37,6 +37,7 @@ static struct swit switches[] = {
        { NULL, 0 }
 };
 
+char *version=VERSION;
 
 #define NFILES 32
 
@@ -75,11 +76,14 @@ static void printone(struct mailname *);
 int
 main(int argc, char **argv)
 {
-       int filep=0, naddrs=0, n;
+       int naddrs=0, n;
        char *cp;
        char buf[BUFSIZ], **argp;
-       char **arguments, *files[NFILES];
+       char **arguments;
+       char *folder = NULL;
        FILE *in;
+       struct msgs_array msgs = {0};
+       struct msgs_array files = {0};
 
        setlocale(LC_ALL, "");
        invo_name = mhbasename(argv[0]);
@@ -139,22 +143,27 @@ main(int argc, char **argv)
                                continue;
                        }
                }
-               if (filep > NFILES) {
-                       adios(EX_USAGE, NULL, "too many files (more than %d)",
-                                       NFILES);
+               if (*cp == '+' || *cp == '@') {
+                       if (folder) {
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
+                       } else {
+                               folder = mh_xstrdup(expandfol(cp));
+                       }
                } else {
-                       files[filep++] = cp;
+                       app_msgarg(&msgs, cp);
                }
        }
-       files[filep] = NULL;
-       if (!filep) {
+       if (!msgs.size) {
                adios(EX_USAGE, NULL, "usage: %s [switches] file ...", invo_name);
        }
        if (!toccsw && !dccsw && !bccsw) {
                adios(EX_USAGE, NULL, "use at least one of: -tocc -dcc -bcc");
        }
-       for (filep=0; files[filep]; filep++) {
-               process(files[filep]);
+       if (parse_msgs(&msgs, folder, &files) < 0) {
+               exit(EX_IOERR);
+       }
+       for (size_t filep = 0; filep < files.size; filep++) {
+               process(files.msgs[filep]);
        }
 
        cmd = add("ali -list", NULL);