allow msgs as parameters for whom
authorPhilipp Takacs <philipp@bureaucracy.de>
Sun, 5 Mar 2017 16:55:00 +0000 (17:55 +0100)
committerPhilipp Takacs <philipp@bureaucracy.de>
Tue, 7 Mar 2017 14:08:42 +0000 (15:08 +0100)
now you can write ``whom c'' instand of ``whom `mhpath c`''

h/utils.h
sbr/Makefile.in
sbr/parse_msgs.c [new file with mode: 0644]
uip/whom.c

index c0d2835..bed9188 100644 (file)
--- a/h/utils.h
+++ b/h/utils.h
@@ -17,3 +17,4 @@ struct msgs_array {
 };
 
 void app_msgarg(struct msgs_array *, char *);
+int parse_msgs(const struct msgs_array *, char *, struct msgs_array *);
index 02038e7..58cf5c7 100644 (file)
@@ -72,7 +72,7 @@ SRCS = addrsbr.c ambigsw.c brkstring.c  \
        smatch.c snprintb.c strcasecmp.c  \
        strindex.c trim.c trimcpy.c uprf.c vfgets.c fmt_def.c  \
        mf.c utils.c m_mktemp.c seq_msgstats.c \
-       unquote.c encode_rfc2047.c
+       unquote.c encode_rfc2047.c parse_msgs.c
 
 OBJS =  $(SRCS:.c=.o)
 
diff --git a/sbr/parse_msgs.c b/sbr/parse_msgs.c
new file mode 100644 (file)
index 0000000..00d9fb8
--- /dev/null
@@ -0,0 +1,50 @@
+#include <h/mh.h>
+#include <h/utils.h>
+
+int
+parse_msgs(const struct msgs_array *msgs, char *folder, struct msgs_array *files)
+{
+       int ret = 0;
+       char *msgnam;
+       struct msgs *f;
+       char *path;
+
+       if (folder) {
+               path = toabsdir(folder);
+       } else {
+               path = toabsdir(getcurfol());
+       }
+
+       path = mh_xstrdup(path);
+       path = add("/", path);
+
+       f = folder_read(path);
+
+       if (f == NULL) {
+               return -1;
+       }
+
+       for (size_t i = 0; i < msgs->size; i++) {
+
+               if (*(msgs->msgs[i]) == '.' || *(msgs->msgs[i]) == '/') {
+                               app_msgarg(files, msgs->msgs[i]);
+                               continue;
+               }
+
+               if (!m_convert(f, msgs->msgs[i])) {
+                       ret++;
+               }
+       }
+
+       for (size_t i = f->lowsel; i <= f->hghsel; i++) {
+               if (is_selected(f, i)) {
+                       msgnam = mh_xstrdup(path);
+                       msgnam = add(m_name(i), msgnam);
+                       app_msgarg(files, msgnam);
+               }
+       }
+
+       folder_free(f);
+
+       return ret;
+}
index 64ec7c9..e664f4b 100644 (file)
@@ -76,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]);
@@ -140,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);