mlist: read directory names from stdin when used non-interactively

Closes #7.
pull/10/head
Christian Neukirchen 8 years ago
parent 2ef903a065
commit 6464ba5845

@ -20,7 +20,7 @@ all: $(ALL)
$(ALL) : % : %.o $(ALL) : % : %.o
maddr magrep mdeliver mexport mflag mgenmid mhdr mpick mscan msed mshow \ maddr magrep mdeliver mexport mflag mgenmid mhdr mpick mscan msed mshow \
msort mthread : blaze822.o mymemmem.o mytimegm.o 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 mthread : seq.o slurp.o
maddr magrep mhdr mpick mscan mshow : rfc2047.o maddr magrep mhdr mpick mscan mshow : rfc2047.o
magrep mshow : rfc2045.o magrep mshow : rfc2045.o

@ -1,4 +1,4 @@
.Dd July 22, 2016 .Dd December 13, 2016
.Dt MLIST 1 .Dt MLIST 1
.Os .Os
.Sh NAME .Sh NAME
@ -15,12 +15,15 @@
.Op Fl N | Fl n | Fl C | Fl c .Op Fl N | Fl n | Fl C | Fl c
.br .br
.Op Fl i .Op Fl i
.Ar dirs\ ... .Op Ar dirs\ ...
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
lists all messages in the Maildir folders lists all messages in the Maildir folders
.Ar dirs .Ar dirs
line by line. line by line.
If used non-interactively and no folders are given,
.Nm
reads directory names from standard input.
.Pp .Pp
The options are as follows: The options are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds

@ -11,6 +11,8 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "blaze822.h"
#define lc(c) ((c) | 0x20) #define lc(c) ((c) | 0x20)
#define uc(c) ((c) & 0xdf) #define uc(c) ((c) & 0xdf)
@ -158,6 +160,56 @@ listdir(char *dir)
} }
#endif #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 int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -189,14 +241,11 @@ main(int argc, char *argv[])
"Usage: mlist [-DFPRST] [-X str]\n" "Usage: mlist [-DFPRST] [-X str]\n"
" [-dfprst] [-x str]\n" " [-dfprst] [-x str]\n"
" [-N | -n | -C | -c]\n" " [-N | -n | -C | -c]\n"
" [-i] dirs...\n" " [-i] [dirs...]\n"
); );
exit(1); exit(1);
} }
if (optind == argc)
goto usage;
int i; int i;
for (i = 0, flagsum = 0, flagset = 0; (size_t)i < sizeof flags; i++) { for (i = 0, flagsum = 0, flagset = 0; (size_t)i < sizeof flags; i++) {
@ -206,53 +255,10 @@ main(int argc, char *argv[])
flagsum++; flagsum++;
} }
for (i = optind; i < argc; i++) { if (optind == argc && isatty(0))
struct stat st; goto usage;
if (stat(argv[i], &st) < 0) else
continue; blaze822_loop(argc-optind, argv+optind, listarg);
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 (iflag && imatched) if (iflag && imatched)
printf("%6ld unseen %3ld flagged %6ld msg\n", printf("%6ld unseen %3ld flagged %6ld msg\n",

Loading…
Cancel
Save