git: 9front

Download patch

ref: 200434baba1610a070122d3c59f95f3667654b43
parent: 70853564b4b6bb2053ee0aa8f57a2120fe29b42b
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Oct 18 13:32:25 EDT 2025

upas/fs: give imap indexes a stable name

currently, the imap index name depends on how an imap inbox is opened;
this is silly, and can lead to different inboxes clobbering each others
index, leading to a spurious sync from scratch and different parallel
mail boxes stomping on each other.

Change to an index format that does not depend on how you open an inbox

--- a/sys/src/cmd/upas/fs/imap.c
+++ b/sys/src/cmd/upas/fs/imap.c
@@ -1113,15 +1113,15 @@
 	free(imap);
 }
 
-static char*
-mkmbox(Imap *imap, char* name, char *p, char *e)
+static void
+setmbpath(Imap *imap, char *p, char *e)
 {
 	p = seprint(p, e, "%s/box/%s/imap.%s", MAILROOT, getlog(), imap->host);
-	if(imap->user && strcmp(imap->user, getlog()))
+	if(imap->user != nil && strcmp(imap->user, getlog()) != 0)
 		p = seprint(p, e, ".%s", imap->user);
-	if(cistrcmp(name, "mbox"))
-		p = seprint(p, e, ".%s", name);
-	return p;
+	if(imap->mbox != nil)
+		p = seprint(p, e, ".%s", imap->mbox);
+	assert(p+1 != e);
 }
 
 static char*
@@ -1152,7 +1152,7 @@
 		return r;
 	free(imap->mbox);
 	imap->mbox = smprint("%s", new);
-	mkmbox(imap, mb->name, mb->path, mb->path + sizeof mb->path);
+	setmbpath(imap, mb->path, mb->path + sizeof mb->path);
 	return 0;
 }
 
@@ -1199,7 +1199,7 @@
 		imap->mbox = strdup("inbox");
 	else
 		imap->mbox = strdup(f[4]);
-	mkmbox(imap, mb->name, mb->path, mb->path + sizeof mb->path);
+	setmbpath(imap, mb->path, mb->path + sizeof mb->path);
 	mb->aux = imap;
 	mb->sync = imap4sync;
 	mb->close = imap4close;
--