From: Philipp Takacs Date: Sun, 5 Mar 2017 16:55:00 +0000 (+0100) Subject: allow msgs as parameters for whom X-Git-Tag: mmh-0.4~46 X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=5b483b0b8517541a8359d7049b4497c6efcb117e;p=mmh allow msgs as parameters for whom now you can write ``whom c'' instand of ``whom `mhpath c`'' --- diff --git a/h/utils.h b/h/utils.h index c0d2835..bed9188 100644 --- 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 *); diff --git a/sbr/Makefile.in b/sbr/Makefile.in index 02038e7..58cf5c7 100644 --- a/sbr/Makefile.in +++ b/sbr/Makefile.in @@ -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 index 0000000..00d9fb8 --- /dev/null +++ b/sbr/parse_msgs.c @@ -0,0 +1,50 @@ +#include +#include + +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; +} diff --git a/uip/whom.c b/uip/whom.c index 64ec7c9..e664f4b 100644 --- a/uip/whom.c +++ b/uip/whom.c @@ -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);