summary refs log tree commit diff
path: root/list.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-12 19:20:26 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-12 19:20:26 +0200
commit698789336dbbaa460fd7132ff2e40fd532893b5e (patch)
tree7d2fa8bc0d73cbbac4f634b0e7c5452ffc14db2d /list.c
parent89e5dedf8b683e40b578b9211615beabfe58fa68 (diff)
downloadmblaze-698789336dbbaa460fd7132ff2e40fd532893b5e.tar.gz
mblaze-698789336dbbaa460fd7132ff2e40fd532893b5e.tar.xz
mblaze-698789336dbbaa460fd7132ff2e40fd532893b5e.zip
list: count summary with -i
Diffstat (limited to 'list.c')
-rw-r--r--list.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/list.c b/list.c
index 7b7f02d..cbbdd9d 100644
--- a/list.c
+++ b/list.c
@@ -38,6 +38,11 @@ static int flagsum;
 static int flagset;
 static int Nflag;
 static int Cflag;
+static int iflag;
+
+static long icount;
+static long iseen;
+static long iflagged;
 
 void
 list(char *prefix, char *file)
@@ -59,6 +64,21 @@ list(char *prefix, char *file)
 			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) {
 		fputs(prefix, stdout);
 		putc('/', stdout);
@@ -139,7 +159,7 @@ int
 main(int argc, char *argv[])
 {
 	int c;
-	while ((c = getopt(argc, argv, "PRSTDFprstdfNnCcm:")) != -1)
+	while ((c = getopt(argc, argv, "PRSTDFprstdfNnCcim:")) != -1)
 		switch(c) {
 		case 'P': case 'R': case 'S': case 'T': case 'D': case 'F':
 			flags[(unsigned int)c] = 1;
@@ -151,6 +171,7 @@ main(int argc, char *argv[])
 		case 'n': Nflag = -1; break;
 		case 'C': Cflag = 1; break;
 		case 'c': Cflag = -1; break;
+		case 'i': iflag = 1; break;
 		case 'm': // XXX todo
 		default:
 			// XXX usage
@@ -175,6 +196,14 @@ main(int argc, char *argv[])
 			struct stat st2;
 			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]);
 			if (stat(subdir, &st2) == 0) {
 				maildir = 1;
@@ -191,11 +220,23 @@ main(int argc, char *argv[])
 
 			if (!maildir)
 				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)) {
 			list(0, argv[i]);
 		}
         }
 
+	if (icount || iseen || iflagged)
+		printf("%6ld unseen  %3ld flagged  %6ld msg\n",
+		    icount-iseen, iflagged, icount);
+
 exit(0);
 
 	exit(EXIT_SUCCESS);