shithub: Nail

Download patch

ref: 4f6225a9e1e45084b8d409e79f689dc51f1ec28c
parent: fa197540ea4e5adc7e8875bd3ca8f080b46a3b4f
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Feb 7 23:27:46 EST 2021

message view: read subparts into root message

This allows nested multipart messages to be rendered
correctly.

--- a/mesg.c
+++ b/mesg.c
@@ -136,7 +136,7 @@
 }
 
 static Mesg*
-readparts(Mesg *m)
+readparts(Mesg *r, Mesg *m)
 {
 	char *dpath, *apath;
 	int n, i, dfd;
@@ -168,18 +168,18 @@
 		if(a == nil)
 			continue;
 		if(strncmp(a->type, "multipart/", strlen("multipart/")) == 0){
-			sub = readparts(a);
+			sub = readparts(r, a);
 			if(sub != a)
 				m->body = sub;
 			continue;
 		} 
-		if(m->nparts >= m->xparts)
-			m->parts = erealloc(m->parts, (2 + m->nparts*2)*sizeof(Mesg*));
-		m->parts[m->nparts++] = a;
-		if(m->body == nil && strcmp(a->type, "text/plain") == 0)
-			m->body = a;
-		else if(m->body == nil && strcmp(a->type, "text/html") == 0)
-			m->body = a;
+		if(r->nparts >= r->xparts)
+			r->parts = erealloc(r->parts, (2 + r->nparts*2)*sizeof(Mesg*));
+		r->parts[r->nparts++] = a;
+		if(r->body == nil && strcmp(a->type, "text/plain") == 0)
+			r->body = a;
+		else if(r->body == nil && strcmp(a->type, "text/html") == 0)
+			r->body = a;
 	}
 	free(d);
 	if(m->body == nil)
@@ -532,7 +532,7 @@
 	int rfd;
 	Mesg *b;
 
-	b = readparts(m);
+	b = readparts(m, m);
 	path = estrjoin(mbox.path, b->name, "body", nil);
 	if(strcmp(b->type, "text/html") == 0)
 		rfd = htmlfmt(m, path);