list: count summary with -i

pull/1/merge
Christian Neukirchen 8 years ago
parent 89e5dedf8b
commit 698789336d

@ -38,6 +38,11 @@ static int flagsum;
static int flagset; static int flagset;
static int Nflag; static int Nflag;
static int Cflag; static int Cflag;
static int iflag;
static long icount;
static long iseen;
static long iflagged;
void void
list(char *prefix, char *file) list(char *prefix, char *file)
@ -59,6 +64,21 @@ list(char *prefix, char *file)
return; return;
} }
if (iflag) {
char *f = strstr(file, ":2,");
if (!f)
return;
icount++;
while (*f) {
if (*f == 'S')
iseen++;
if (*f == 'F')
iflagged++;
f++;
}
return;
}
if (prefix) { if (prefix) {
fputs(prefix, stdout); fputs(prefix, stdout);
putc('/', stdout); putc('/', stdout);
@ -139,7 +159,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "PRSTDFprstdfNnCcm:")) != -1) while ((c = getopt(argc, argv, "PRSTDFprstdfNnCcim:")) != -1)
switch(c) { switch(c) {
case 'P': case 'R': case 'S': case 'T': case 'D': case 'F': case 'P': case 'R': case 'S': case 'T': case 'D': case 'F':
flags[(unsigned int)c] = 1; flags[(unsigned int)c] = 1;
@ -151,6 +171,7 @@ main(int argc, char *argv[])
case 'n': Nflag = -1; break; case 'n': Nflag = -1; break;
case 'C': Cflag = 1; break; case 'C': Cflag = 1; break;
case 'c': Cflag = -1; break; case 'c': Cflag = -1; break;
case 'i': iflag = 1; break;
case 'm': // XXX todo case 'm': // XXX todo
default: default:
// XXX usage // XXX usage
@ -175,6 +196,14 @@ main(int argc, char *argv[])
struct stat st2; struct stat st2;
int maildir = 0; int maildir = 0;
long gcount = icount;
long gseen = iseen;
long gflagged = iflagged;
icount = 0;
iseen = 0;
iflagged = 0;
snprintf(subdir, sizeof subdir, "%s/cur", argv[i]); snprintf(subdir, sizeof subdir, "%s/cur", argv[i]);
if (stat(subdir, &st2) == 0) { if (stat(subdir, &st2) == 0) {
maildir = 1; maildir = 1;
@ -191,11 +220,23 @@ main(int argc, char *argv[])
if (!maildir) if (!maildir)
listdir(argv[i]); listdir(argv[i]);
if (iflag && icount)
printf("%6ld unseen %3ld flagged %6ld msg %s\n",
icount-iseen, iflagged, icount, argv[i]);
icount = gcount;
iseen = gseen;
iflagged = gflagged;
} else if (S_ISREG(st.st_mode)) { } else if (S_ISREG(st.st_mode)) {
list(0, argv[i]); list(0, argv[i]);
} }
} }
if (icount || iseen || iflagged)
printf("%6ld unseen %3ld flagged %6ld msg\n",
icount-iseen, iflagged, icount);
exit(0); exit(0);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

Loading…
Cancel
Save