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)
--- /dev/null
+#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;
+}
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]);
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);