git: 9front

Download patch

ref: 19657859166321fc3e32d1ab7e652dcc4c767e19
parent: 5e41af191ffbbcbd654d4425e523422c68586f1f
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Oct 23 21:10:05 EDT 2025

upas/Mail: improve exit behavior for mailbox list Del (thanks flowerss)

--- a/sys/src/cmd/upas/Mail/mail.h
+++ b/sys/src/cmd/upas/Mail/mail.h
@@ -136,7 +136,8 @@
 
 	Mesg	*openmesg;
 	Comp	*opencomp;
-	int	canquit;
+	int	quitwopen;
+	int quitdirty;
 
 	Channel	*see;
 	Channel	*show;
--- a/sys/src/cmd/upas/Mail/mbox.c
+++ b/sys/src/cmd/upas/Mail/mbox.c
@@ -796,10 +796,11 @@
 {
 	Mesg *m;
 	Comp *c;
+	char d;
 
-	if(mbox.nopen > 0 && !mbox.canquit){
+	if(mbox.nopen > 0 && !mbox.quitwopen){
 		fprint(2, "Del: %d open messages\n", mbox.nopen);
-		mbox.canquit = 1;
+		mbox.quitwopen = 1;
 		return;
 	}
 	for(m = mbox.openmesg; m != nil; m = m->qnext)
@@ -806,7 +807,15 @@
 		fprint(m->ctl, "del\n");
 	for(c = mbox.opencomp; c != nil; c = c->qnext)
 		fprint(c->ctl, "del\n");
-	fprint(mbox.ctl, "del\n");
+	/* check if mbox has unsaved changes by reading dirty flag before closing */
+	pread(mbox.ctl, &d, 1, 58);
+	if(d == '1' && !mbox.quitdirty){
+		fprint(2, "Del: unsaved changes in mailbox\n");
+		mbox.quitdirty = 1;
+		return;
+	}
+	else
+		fprint(mbox.ctl, "delete\n");
 	threadexitsall(nil);
 }
 
@@ -991,8 +1000,10 @@
 			}
 		if(p->fn == nil)
 			winreturn(&mbox, ev);
-		else if(p->fn != quitall)
-			mbox.canquit = 0;
+		else if(p->fn != quitall) {
+			mbox.quitwopen = 0;
+			mbox.quitdirty = 0;
+		}
 		break;
 	}
 }
--