shithub: Nail

Download patch

ref: df047110e8f44bead962269dbfca2062bceb18f4
parent: 479b69e45275a5304b7df014c8f0f0ad60423c53
author: Ori Bernstein <[email protected]>
date: Fri Nov 13 19:07:43 EST 2020

split state flags from message flags: fix overclearing on message modify.

--- a/mail.h
+++ b/mail.h
@@ -12,14 +12,16 @@
 };
 
 enum {
-	Fdummy	= 1<<0,	/* message placeholder */
-	Ftoplev	= 1<<1,	/* not a response to anything */
-	Fopen	= 1<<2,	/* opened for viewing */
+	Sdummy	= 1<<0,	/* message placeholder */
+	Stoplev	= 1<<1,	/* not a response to anything */
+	Sopen	= 1<<2,	/* opened for viewing */
+};
 
-	Fresp	= 1<<3,	/* has been responded to */
-	Fseen	= 1<<4,	/* has been viewed */
-	Fdel	= 1<<5, /* was deleted */
-	Ftodel	= 1<<6,	/* pending deletion */
+enum {
+	Fresp	= 1<<0,	/* has been responded to */
+	Fseen	= 1<<1,	/* has been viewed */
+	Fdel	= 1<<2, /* was deleted */
+	Ftodel	= 1<<3,	/* pending deletion */
 };
 
 enum {
@@ -78,6 +80,7 @@
 
 	/* bookkeeping */
 	char	*name;
+	int	state;
 	int	flags;
 	u32int	hash;
 	char	quitting;
--- a/mbox.c
+++ b/mbox.c
@@ -143,7 +143,7 @@
 				break;
 			o += p->child[i]->nsub + 1;
 		}
-		if(!(p->flags & Fdummy)){
+		if(!(p->state & Sdummy)){
 			o++;
 			d++;
 		}
@@ -154,9 +154,9 @@
 		m = mbox.mesg[i];
 		if(m == p)
 			break;
-		if(m->flags & Ftoplev){
+		if(m->state & Stoplev){
 			n += mbox.mesg[i]->nsub;
-			if(!(m->flags & Fdummy))
+			if(!(m->state & Sdummy))
 				n++;
 		}
 
@@ -208,7 +208,7 @@
 	int i;
 
 	/* Dummies don't go in the table */
-	if(m->flags & Fdummy)
+	if(m->state & Sdummy)
 		return;
 	i = m->hash % mbox.hashsz;
 	while(1){
@@ -301,7 +301,7 @@
 	Mesg *m;
 
 	m = emalloc(sizeof(Mesg));
-	m->flags |= Fdummy|Ftoplev;
+	m->state |= Sdummy|Stoplev;
 	m->messageid = estrdup(msgid);
 	m->hash = strhash(msgid);
 	m->time = time;
@@ -365,7 +365,7 @@
 		addmesg(m, ins);
 
 	if(!threadsort || m->inreplyto == nil){
-		m->flags |= Ftoplev;
+		m->state |= Stoplev;
 		return m;
 	}
 
@@ -433,7 +433,7 @@
 	char *sep, *flag, *dots;
 	int i, width;
 
-	if(!(m->flags & Fdummy)){
+	if(!(m->state & Sdummy)){
 		dots = "";
 		flag = "★";
 		sep = depth ? "\t" : "";
@@ -543,7 +543,7 @@
 		if(p != nil)
 			addchild(p, c);
 		else
-			c->flags |= Ftoplev;
+			c->state |= Stoplev;
 	}
 }
 
@@ -562,7 +562,7 @@
 		sysfatal("open mbox: %r");
 	while(i < mbox.nmesg){
 		m = mbox.mesg[i];
-		if((m->flags & Fopen) || !(m->flags & (Fdel|Ftodel))){
+		if((m->state & Sopen) || !(m->flags & (Fdel|Ftodel))){
 			i++;
 			continue;
 		}
@@ -606,7 +606,7 @@
 	bfd = bwinopen(&mbox, "data", OWRITE);
 	for(i = 0; i < mbox.nmesg; i++){
 		m = mbox.mesg[i];
-		if(mbox.view == Vflat || m->flags & (Fdummy|Ftoplev))
+		if(mbox.view == Vflat || m->state & (Sdummy|Stoplev))
 			showmesg(bfd, m, 0, 1);
 	}
 	Bterm(bfd);
@@ -669,7 +669,7 @@
 		/* Bump whole thread up in list */
 		if(r->nsub > 0){
 			ln = mesglineno(r, nil);
-			nr = r->nsub + (r->flags & Fdummy) ? 0 : 1;
+			nr = r->nsub + (r->state & Sdummy) ? 0 : 1;
 			assert(nr > 0);
 			fprint(mbox.addr, "%d,%d", ln, ln+nr-1);
 			write(mbox.data, "", 0);
--- a/mesg.c
+++ b/mesg.c
@@ -433,7 +433,7 @@
 		}
 	mbox.nopen--;
 	m->qnext = nil;
-	m->flags &= ~Fopen;
+	m->state &= ~Sopen;
 	winclose(m);
 	threadexits(nil);
 }
@@ -487,9 +487,7 @@
 int
 mesgmatch(Mesg *m, char *name, char *digest)
 {
-	if(m->flags & Fdummy)
-		return 0;
-	if(strcmp(m->name, name) == 0)
+	if(!(m->state & Sdummy) && strcmp(m->name, name) == 0)
 		return digest == nil || strcmp(m->digest, digest) == 0;
 	return 0;
 }
@@ -515,11 +513,11 @@
 	int fd;
 
 	m = mesglookup(name, digest);
-	if(m == nil || (m->flags & Fopen))
+	if(m == nil || (m->state & Sopen))
 		return nil;
 
-	assert(!(m->flags & Fdummy));
-	m->flags |= Fopen;
+	assert(!(m->state & Sdummy));
+	m->state |= Sopen;
 	if(!(m->flags & Fseen)){
 		m->flags |= Fseen;
 		path = estrjoin(mbox.path, "/", m->name, "/flags", nil);