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

Closes #7.
This commit is contained in:
Christian Neukirchen 2016-12-13 15:21:00 +01:00
parent 2ef903a065
commit 6464ba5845
3 changed files with 63 additions and 54 deletions

View File

@ -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

View File

@ -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

108
mlist.c
View File

@ -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",