From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from outgoing.selfhost.de ([82.98.82.6]) by ewsd; Tue Mar 3 16:41:33 EST 2020 Received: (qmail 24021 invoked from network); 3 Mar 2020 21:41:20 -0000 Received: from unknown (HELO mx03.bss-wf.de) (postmaster@emdtgvmf.mail.selfhost.de@84.150.47.200) by mailout.selfhost.de with ESMTPA; 3 Mar 2020 21:41:20 -0000 Received: by mx03.bss-wf.de (Postfix, from userid 1000) id BD4E53DDF1; Tue, 3 Mar 2020 22:41:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mx03 X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.2 Received: from 9nb.fritz.box (p4FD3F2D5.dip0.t-ipconnect.de [79.211.242.213]) by mx03.bss-wf.de (Postfix) with ESMTPSA id C93AD3DD9E for <9front@9front.org>; Tue, 3 Mar 2020 22:41:14 +0100 (CET) Message-ID: <5150F120038735FED495F8EF5813A939@yourdomain.dom> To: 9front@9front.org Subject: [PATCH] add option to faces(1) for only showing unread mail Date: Tue, 3 Mar 2020 22:41:12 +0100 From: theinicke@bss-wf.de MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: method HTTP deep-learning package-scale solution 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 #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; iattr, "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 */