shithub: Nail

Download patch

ref: cadbd8b4090683f1634cc580ef6f5d9371c3f07a
parent: 8f73c6436a0a0a39f6e1de79b4fd6f21af38d841
author: Ori Bernstein <[email protected]>
date: Wed Nov 4 01:26:42 EST 2020

handle recursive multipart messages

--- a/mbox.c
+++ b/mbox.c
@@ -612,8 +612,10 @@
 static void
 mbquit(char **, int)
 {
-	if(mbox.nopen > 0)
-		fprint(2, "Del: %d open messages", mbox.nopen);
+	if(mbox.nopen > 0){
+		fprint(2, "Del: %d open messages\n", mbox.nopen);
+		return;
+	}
 	winclose(&mbox);
 	threadexitsall(nil);
 }
--- a/mesg.c
+++ b/mesg.c
@@ -133,7 +133,7 @@
 {
 	char *dpath, *apath;
 	int n, i, dfd;
-	Mesg *a, *best;
+	Mesg *a, *sub, *best;
 	Dir *d;
 
 	dpath = estrjoin(mbox.path, m->name, nil);
@@ -148,8 +148,7 @@
 		sysfatal("%s read: %r", mbox.path);
 
 	best = nil;
-	m->attachments = emalloc(n*sizeof(Mesg*));
-	m->nattachments = 0;
+	m->attachments = erealloc(m->attachments, (m->nattachments + n)*sizeof(Mesg*));
 	for(i = 0; i < n; i++){
 		if(d[i].qid.type != QTDIR)
 			continue;
@@ -159,6 +158,12 @@
 		free(apath);
 		if(a == nil)
 			continue;
+		if(strncmp(a->type, "multipart/", strlen("multipart/")) == 0){
+			sub = readparts(a);
+			if(sub != a)
+				best = sub;
+			continue;
+		} 
 		m->attachments[m->nattachments++] = a;
 		if(a->filename != nil || a->disposition != nil && strcmp(a->disposition, "inline") != 0)
 			continue;