shithub: Nail

Download patch

ref: 220d88a590fb598cb1bf1bbc031e3a4506fe6eab
parent: 2bd4856a42fb0f428ec848c658396c850f1b77e5
author: Ori Bernstein <[email protected]>
date: Sat Jan 23 02:45:55 EST 2021

mbox: adjust nsub correctly when wiring dummy in

When flipping a dummy over to a concrete message,
we can have more than one message being added to
the parent. Specifically:

	[D]
	   a
	   b

flipping to:

	x
      y
        D
          a
          b

adds 3 to the nsub for x and y.

--- a/mbox.c
+++ b/mbox.c
@@ -169,7 +169,7 @@
 }
 
 static int
-addchild(Mesg *p, Mesg *m)
+addchild(Mesg *p, Mesg *m, int d)
 {
 	Mesg *q;
 
@@ -183,7 +183,7 @@
 			q->time = m->time;
 	}
 	for(q = p; q != nil; q = q->parent)
-		q->nsub++;
+		q->nsub += d;
 	p->child = erealloc(p->child, ++p->nchild*sizeof(Mesg*));
 	p->child[p->nchild - 1] = m;
 	qsort(p->child, p->nchild, sizeof(Mesg*), rcmpmesg);
@@ -343,6 +343,7 @@
 load(char *name, char *digest, int ins)
 {
 	Mesg *m, *p;
+	int d;
 
 	if(strncmp(name, mbox.path, strlen(mbox.path)) == 0)
 		name += strlen(mbox.path);
@@ -352,8 +353,10 @@
 	if(digest != nil && strcmp(digest, m->digest) != 0)
 		goto error;
 	/* if we already have a dummy, populate it */
+	d = 1;
 	p = lookupid(m->messageid);
 	if(p != nil && (p->state & Sdummy)){
+		d = p->nsub + 1;
 		m->child = p->child;
 		m->nchild = p->nchild;
 		m->nsub = p->nsub;
@@ -380,7 +383,7 @@
 	p = lookupid(m->inreplyto);
 	if(p == nil)
 		p = placeholder(m->inreplyto, m->time, ins);
-	if(!addchild(p, m))
+	if(!addchild(p, m, d))
 		m->state |= Stoplev;
 	return m;
 error:
@@ -669,7 +672,7 @@
 		c = m->child[i];
 		c->parent = nil;
 		if(p != nil)
-			addchild(p, c);
+			addchild(p, c, 1);
 		else
 			c->state |= Stoplev;
 	}