aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-12-13 15:21:00 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2016-12-13 15:21:00 +0100
commit6464ba584539365219f84326012fee87f71bde54 (patch)
tree19edcfcf7cf6145d0c368a2c52713cec40dad6dc
parent2ef903a06547f9461dd6769baf7a19f4dd17dc39 (diff)
downloadmblaze-6464ba584539365219f84326012fee87f71bde54.tar.gz
mlist: read directory names from stdin when used non-interactively
Closes #7.
-rw-r--r--Makefile2
-rw-r--r--man/mlist.17
-rw-r--r--mlist.c108
3 files changed, 63 insertions, 54 deletions
diff --git a/Makefile b/Makefile
index 451e1e3..df705cc 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ all: $(ALL)
$(ALL) : % : %.o
maddr magrep mdeliver mexport mflag mgenmid mhdr mpick mscan msed mshow \
msort mthread : blaze822.o mymemmem.o mytimegm.o
-maddr magrep mexport mflag mgenmid mhdr mpick mscan msed mseq mshow msort \
+maddr magrep mexport mflag mgenmid mhdr mlist mpick mscan msed mseq mshow msort \
mthread : seq.o slurp.o
maddr magrep mhdr mpick mscan mshow : rfc2047.o
magrep mshow : rfc2045.o
diff --git a/man/mlist.1 b/man/mlist.1
index 89fc673..1c5a472 100644
--- a/man/mlist.1
+++ b/man/mlist.1
@@ -1,4 +1,4 @@
-.Dd July 22, 2016
+.Dd December 13, 2016
.Dt MLIST 1
.Os
.Sh NAME
@@ -15,12 +15,15 @@
.Op Fl N | Fl n | Fl C | Fl c
.br
.Op Fl i
-.Ar dirs\ ...
+.Op Ar dirs\ ...
.Sh DESCRIPTION
.Nm
lists all messages in the Maildir folders
.Ar dirs
line by line.
+If used non-interactively and no folders are given,
+.Nm
+reads directory names from standard input.
.Pp
The options are as follows:
.Bl -tag -width Ds
diff --git a/mlist.c b/mlist.c
index 0fade35..0f7bd88 100644
--- a/mlist.c
+++ b/mlist.c
@@ -11,6 +11,8 @@
#include <string.h>
#include <unistd.h>
+#include "blaze822.h"
+
#define lc(c) ((c) | 0x20)
#define uc(c) ((c) & 0xdf)
@@ -158,6 +160,56 @@ listdir(char *dir)
}
#endif
+void
+listarg(char *arg)
+{
+ struct stat st;
+ if (stat(arg, &st) < 0)
+ return;
+ if (S_ISDIR(st.st_mode)) {
+ char subdir[PATH_MAX];
+ struct stat st2;
+ int maildir = 0;
+
+ long gcount = icount;
+ long gunseen = iunseen;
+ long gflagged = iflagged;
+ long gmatched = imatched;
+
+ icount = 0;
+ iunseen = 0;
+ iflagged = 0;
+
+ snprintf(subdir, sizeof subdir, "%s/cur", arg);
+ if (stat(subdir, &st2) == 0) {
+ maildir = 1;
+ if (Cflag >= 0 && Nflag <= 0)
+ listdir(subdir);
+ }
+
+ snprintf(subdir, sizeof subdir, "%s/new", arg);
+ if (stat(subdir, &st2) == 0) {
+ maildir = 1;
+ if (Nflag >= 0 && Cflag <= 0)
+ listdir(subdir);
+ }
+
+ if (!maildir)
+ listdir(arg);
+
+ if (iflag && imatched)
+ printf("%6ld unseen %3ld flagged %6ld msg %s\n",
+ iunseen, iflagged, icount, arg);
+
+ icount = gcount;
+ iunseen = gunseen;
+ iflagged = gflagged;
+ imatched = gmatched;
+ } else if (S_ISREG(st.st_mode)) {
+ list(0, arg);
+ }
+}
+
int
main(int argc, char *argv[])
{
@@ -189,14 +241,11 @@ main(int argc, char *argv[])
"Usage: mlist [-DFPRST] [-X str]\n"
" [-dfprst] [-x str]\n"
" [-N | -n | -C | -c]\n"
- " [-i] dirs...\n"
+ " [-i] [dirs...]\n"
);
exit(1);
}
- if (optind == argc)
- goto usage;
-
int i;
for (i = 0, flagsum = 0, flagset = 0; (size_t)i < sizeof flags; i++) {
@@ -206,53 +255,10 @@ main(int argc, char *argv[])
flagsum++;
}
- for (i = optind; i < argc; i++) {
- struct stat st;
- if (stat(argv[i], &st) < 0)
- continue;
- if (S_ISDIR(st.st_mode)) {
- char subdir[PATH_MAX];
- struct stat st2;
- int maildir = 0;
-
- long gcount = icount;
- long gunseen = iunseen;
- long gflagged = iflagged;
- long gmatched = imatched;
-
- icount = 0;
- iunseen = 0;
- iflagged = 0;
-
- snprintf(subdir, sizeof subdir, "%s/cur", argv[i]);
- if (stat(subdir, &st2) == 0) {
- maildir = 1;
- if (Cflag >= 0 && Nflag <= 0)
- listdir(subdir);
- }
-
- snprintf(subdir, sizeof subdir, "%s/new", argv[i]);
- if (stat(subdir, &st2) == 0) {
- maildir = 1;
- if (Nflag >= 0 && Cflag <= 0)
- listdir(subdir);
- }
-
- if (!maildir)
- listdir(argv[i]);
-
- if (iflag && imatched)
- printf("%6ld unseen %3ld flagged %6ld msg %s\n",
- iunseen, iflagged, icount, argv[i]);
-
- icount = gcount;
- iunseen = gunseen;
- iflagged = gflagged;
- imatched = gmatched;
- } else if (S_ISREG(st.st_mode)) {
- list(0, argv[i]);
- }
- }
+ if (optind == argc && isatty(0))
+ goto usage;
+ else
+ blaze822_loop(argc-optind, argv+optind, listarg);
if (iflag && imatched)
printf("%6ld unseen %3ld flagged %6ld msg\n",