shithub: Nail

Download patch

ref: 5d357160775432816ceb80bfabc98375f7db73a5
parent: d765a836933a0ce07b1baaa0758be2f223dcaa3a
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Nov 17 22:09:56 EST 2020

mbox: handle duplicate message ids correctly

We used to treat the previous message as a dummy and
copy the children of the current message into it every
time we encountered one, meaning that every dummy got
a duplicate child list.

Now, we only treat it as a dummy if it's flagged that
way, otherwise we just add the message as normal.

--- a/mbox.c
+++ b/mbox.c
@@ -229,7 +229,7 @@
 	u32int h, i;
 	Mesg *e;
 
-	if(msgid == nil)
+	if(msgid == nil || strlen(msgid) == 0)
 		return nil;
 	h = strhash(msgid);
 	i = h % mbox.hashsz;
@@ -249,11 +249,6 @@
 	Mesg *o, *e, **oldh;
 	int i, oldsz, idx;
 
-	/* add to flat list */
-	if(mbox.nmesg == mbox.mesgsz){
-		mbox.mesgsz *= 2;
-		mbox.mesg = erealloc(mbox.mesg, mbox.mesgsz*sizeof(Mesg*));
-	}
 	/* 
 	 * on initial load, it's faster to append everything then sort,
 	 * but on subsequent messages it's better to just put it in the
@@ -260,6 +255,10 @@
 	 * right place; we don't want to shuffle the already-sorted
 	 * messages.
 	 */
+	if(mbox.nmesg == mbox.mesgsz){
+		mbox.mesgsz *= 2;
+		mbox.mesg = erealloc(mbox.mesg, mbox.mesgsz*sizeof(Mesg*));
+	}
 	if(ins)
 		idx = slotfor(m);
 	else
@@ -352,7 +351,8 @@
 	if(digest != nil && strcmp(digest, m->digest) != 0)
 		goto error;
 	/* if we already have a dummy, populate it */
-	if((p = lookupid(m->messageid)) != nil){
+	p = lookupid(m->messageid);
+	if(p != nil && (p->state & Sdummy)){
 		m->child = p->child;
 		m->nchild = p->nchild;
 		m->nsub = p->nsub;