9front - general discussion about 9front
 help / color / mirror / Atom feed
* [PATCH] add option to faces(1) for only showing unread mail
@ 2020-03-03 21:41 theinicke
  0 siblings, 0 replies; only message in thread
From: theinicke @ 2020-03-03 21:41 UTC (permalink / raw)
  To: 9front

I would like to propose an option to faces(1) for showing faces only for unread messages. This makes the -i option much more useful to me and given the recent changes regarding getting, setting and showing flags, I figured this might be of use for someone besides me.

I have inlined a diff of the changes I have been running for quite some time now and they work well for me. As laid out in the comments and BUGS section this implementation however is not completely correct, because looking up the message via its digest to obtain flag information is too much overhead in my opinion. To make it correct I would suggest including flag information in messages plumbed to seemail (if this is desirable I could make another patch).

--
Tobias Heinicke


diff -r 0dd419f096e2 sys/man/1/faces
--- a/sys/man/1/faces	Sun Mar 01 23:23:01 2020 +0100
+++ b/sys/man/1/faces	Tue Mar 03 22:21:19 2020 +0100
@@ -4,7 +4,7 @@
 .SH SYNOPSIS
 .B faces
 [
-.B -ih
+.B -iuh
 ] [
 .B -m
 .I maildir
@@ -36,7 +36,7 @@
 port,
 typically from
 .BR upas/fs ,
-and is thus notified of message additions and deletions.
+and is thus notified of message additions, modifications and deletions.
 .PP
 Right-clicking on a message icon causes that message to be `plumbed' to
 .BR showmail .
@@ -75,6 +75,14 @@
 upon startup.
 .PP
 The
+.B -u
+option directs
+.I faces to show message icons only
+for messages with read flag not set.
+Causes icons to also be removed
+when messages are modified.
+.PP
+The
 .B -m
 option directs
 .I faces
@@ -122,3 +130,13 @@
 .IR plumber (4),
 .IR face (6),
 .IR plumb (6)
+.SH BUGS
+The
+.B -u
+option honors reading mail from
+multiple imap connections poorly.
+For example read flags on 'new' messages
+are not checked, thus a face for read mail
+may be shown if someone reads their mail
+very fast on another imap connection
+(which is not a upas/fs talking to the known plumber(4)).
diff -r 0dd419f096e2 sys/src/cmd/faces/faces.h
--- a/sys/src/cmd/faces/faces.h	Sun Mar 01 23:23:01 2020 +0100
+++ b/sys/src/cmd/faces/faces.h	Tue Mar 03 22:21:19 2020 +0100
@@ -46,7 +46,7 @@
 extern char	**maildirs;
 extern int	nmaildirs;
 
-Face*	nextface(void);
+Face*	nextface(int);
 void	findbit(Face*);
 void	freeface(Face*);
 void	initplumb(void);
@@ -54,7 +54,7 @@
 void	showmail(Face*);
 void	delete(char*, char*);
 void	freefacefile(Facefile*);
-Face*	dirface(char*, char*);
+Face*	dirface(char*, char*, int);
 void	resized(void);
 int	alreadyseen(char*);
 ulong	dirlen(char*);
diff -r 0dd419f096e2 sys/src/cmd/faces/main.c
--- a/sys/src/cmd/faces/main.c	Sun Mar 01 23:23:01 2020 +0100
+++ b/sys/src/cmd/faces/main.c	Tue Mar 03 22:21:19 2020 +0100
@@ -7,8 +7,9 @@
 #include <bio.h>
 #include "faces.h"
 
-int	history = 0;	/* use old interface, showing history of mailbox rather than current state */
-int	initload = 0;	/* initialize program with contents of mail box */
+int	history = 0;		/* use old interface, showing history of mailbox rather than current state */
+int	initload = 0;		/* initialize program with contents of mail box */
+int	unreadonly = 0;	/* show face only for messages with read flag not set */
 
 enum
 {
@@ -358,18 +359,22 @@
 }
 
 void
-loadmboxfaces(char *maildir)
+loadmboxfaces(char *maildir, int unreadonly)
 {
 	int dirfd;
 	Dir *d;
+	Face *f;
 	int i, n;
 
 	dirfd = open(maildir, OREAD);
 	if(dirfd >= 0){
 		chdir(maildir);
 		while((n = dirread(dirfd, &d)) > 0){
-			for(i=0; i<n; i++)
-				addface(dirface(maildir, d[i].name));
+			for(i=0; i<n; i++) {
+				f = dirface(maildir, d[i].name, unreadonly);
+				if(f != nil)
+					addface(f);
+			}
 			free(d);
 		}
 		close(dirfd);
@@ -475,7 +480,7 @@
 faceproc(void)
 {
 	for(;;)
-		addface(nextface());
+		addface(nextface(unreadonly));
 }
 
 void
@@ -691,6 +696,9 @@
 	case 'i':
 		initload++;
 		break;
+	case 'u':
+		unreadonly++;
+		break;
 	case 'm':
 		addmaildir(EARGF(usage()));
 		maildir = nil;
@@ -716,7 +724,7 @@
 	startproc(mouseproc, Mousep);
 	if(initload)
 		for(i = 0; i < nmaildirs; i++)
-		 loadmboxfaces(maildirs[i]);
+		 loadmboxfaces(maildirs[i], unreadonly);
 	faceproc();
 	fprint(2, "faces: %s process exits\n", procnames[Mainp]);
 	killall(nil);
diff -r 0dd419f096e2 sys/src/cmd/faces/plumb.c
--- a/sys/src/cmd/faces/plumb.c	Sun Mar 01 23:23:01 2020 +0100
+++ b/sys/src/cmd/faces/plumb.c	Tue Mar 03 22:21:19 2020 +0100
@@ -258,7 +258,7 @@
 }
 
 Face*
-nextface(void)
+nextface(int unreadonly)
 {
 	int i;
 	Face *f;
@@ -273,8 +273,17 @@
 			if(m == nil)
 				killall("error on seemail plumb port");
 			t = value(m->attr, "mailtype", "");
-			if(strcmp(t, "modify") == 0)
-				goto Ignore;
+			if(strcmp(t, "modify") == 0) {
+				/* Assume that receiving a modify for message implies that message was read,
+				 * because changed flags on a message still not having been read is a corner case
+				 * which does not justify overhead of message lookup and reading flag changes.
+				 */
+				if(unreadonly != 0) {
+					delete(m->data, value(m->attr, "digest", nil));
+				} else {
+					goto Ignore;
+				}
+			}
 			else if(strcmp(t, "delete") == 0)
 				delete(m->data, value(m->attr, "digest", nil));
 			else if(strcmp(t, "new") == 0)
@@ -330,12 +339,13 @@
 }
 
 Face*
-dirface(char *dir, char *num)
+dirface(char *dir, char *num, int unreadonly)
 {
 	Face *f;
 	char *from, *date;
 	char buf[1024], pwd[1024], *info, *p, *digest;
-	int n, fd;
+	char readflag;
+	int n, fd, i, u;
 	ulong len;
 
 	/*
@@ -361,6 +371,23 @@
 		return nil;
 	}
 	info[n] = '\0';
+
+	/* if unreadonly set, return nil for read message */
+	if(unreadonly != 0) {
+		/* seek to flags */
+		u = n;
+		for(i = 0; i < 3; i++) {
+			while(u > 0 && info[--u] != '\n')
+				;
+		}
+		if(u > 2) {
+			readflag = info[u-2];
+			if(readflag == 's') {
+				return nil;
+			}
+		}
+	}
+	
 	f = emalloc(sizeof(Face));
 	from = iline(info, &p);	/* from */
 	iline(p, &p);	/* to */




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-03 21:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-03 21:41 [PATCH] add option to faces(1) for only showing unread mail theinicke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).