shithub: Nail

Download patch

ref: cecb7780706ac93203bc94a43cf36708b89206c0
parent: 4ba5b6daa92b75a3ec8579e8de9025f02b71088e
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Nov 23 12:28:29 EST 2020

message view: show messages with cyclic replies.

Some messages have an inreplyto field that points at the
message itself. We used to leave these messages orphaned,
and in some cases they'd be dropped from the message list.

This fixes it, so that the messages at least end up
vislble.

--- a/mbox.c
+++ b/mbox.c
@@ -95,11 +95,11 @@
 }
 
 static int
-ideq(Mesg *a, Mesg *b)
+ideq(char *a, char *b)
 {
-	if(a->messageid == nil || b->messageid == nil)
+	if(a == nil || b == nil)
 		return 0;
-	return strcmp(a->messageid, b->messageid) == 0;
+	return strcmp(a, b) == 0;
 }
 
 static int
@@ -175,7 +175,7 @@
 
 	assert(m->parent == nil);
 	for(q = p; q != nil; q = q->parent){
-		if(ideq(m, q)){
+		if(ideq(m->messageid, q->messageid)){
 			fprint(2, "wonky message replies to self\n");
 			return 0;
 		}
@@ -373,15 +373,15 @@
 		addmesg(m, ins);
 	}
 
-	if(!threadsort || m->inreplyto == nil){
+	if(!threadsort || m->inreplyto == nil || ideq(m->messageid, m->inreplyto)){
 		m->state |= Stoplev;
 		return m;
 	}
-
 	p = lookupid(m->inreplyto);
 	if(p == nil)
 		p = placeholder(m->inreplyto, m->time, ins);
-	addchild(p, m);
+	if(!addchild(p, m))
+		m->state |= Stoplev;
 	return m;
 error:
 	mesgfree(m);