9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Subject: [patch] upas: plumb flag updates on messages.
Date: Sun, 8 Dec 2019 12:02:44 -0800	[thread overview]
Message-ID: <27DBD03EAF07864ED33411518EE16A58@eigenstate.org> (raw)

This patch makes 3 changes for the last bit of polish
I wanted in my mail client:

	- It makes upas/fs send plumb messages when a message
	  changes in the background (eg, someone on another imap
	  connection opens a message and sets the read flag)
	- It makes faces not complain when it gets one of these
	  new modify messages.
	- It makes acme/Mail update the flags in the display
	  when it gets one of these messages.

I've been using it for the last week with no issue, and
honestly just forgot that it was there.

diff -r 7f3f8606fc12 sys/src/cmd/faces/plumb.c
--- a/sys/src/cmd/faces/plumb.c	Sun Dec 08 11:58:52 2019 -0800
+++ b/sys/src/cmd/faces/plumb.c	Sun Dec 08 11:59:39 2019 -0800
@@ -273,13 +273,18 @@
 			if(m == nil)
 				killall("error on seemail plumb port");
 			t = value(m->attr, "mailtype", "");
-			if(strcmp(t, "delete") == 0)
+			if(strcmp(t, "modify") == 0)
+				goto Ignore;
+			else if(strcmp(t, "delete") == 0)
 				delete(m->data, value(m->attr, "digest", nil));
-			else if(strcmp(t, "new") != 0)
+			else if(strcmp(t, "new") == 0)
+				for(i=0; i<nmaildirs; i++){
+					if(strncmp(m->data, maildirs[i], strlen(maildirs[i])) == 0)
+						goto Found;
+				}
+			else
 				fprint(2, "faces: unknown plumb message type %s\n", t);
-			else for(i=0; i<nmaildirs; i++)
-				if(strncmp(m->data, maildirs[i], strlen(maildirs[i])) == 0)
-					goto Found;
+		Ignore:
 			plumbfree(m);
 			continue;
 
diff -r 7f3f8606fc12 sys/src/cmd/upas/Mail/dat.h
--- a/sys/src/cmd/upas/Mail/dat.h	Sun Dec 08 11:58:52 2019 -0800
+++ b/sys/src/cmd/upas/Mail/dat.h	Sun Dec 08 11:59:39 2019 -0800
@@ -124,6 +124,7 @@
 
 extern	int		mesgadd(Message*, char*, Dir*, char*);
 extern	void		mesgmenu(Window*, Message*);
+extern	void		mesgmenuselect(Window*, Message*);
 extern	void		mesgmenunew(Window*, Message*);
 extern	void		mesgmenureflag(Window*, Message*);
 extern	int		mesgopen(Message*, char*, char*, Message*, int, char*);
diff -r 7f3f8606fc12 sys/src/cmd/upas/Mail/mail.c
--- a/sys/src/cmd/upas/Mail/mail.c	Sun Dec 08 11:58:52 2019 -0800
+++ b/sys/src/cmd/upas/Mail/mail.c	Sun Dec 08 11:59:39 2019 -0800
@@ -317,6 +317,22 @@
 	}
 }
 
+void
+modmesg(char *name, char *digest)
+{
+	Message *m;
+	char *flags;
+
+	if((m = mesglookupfile(&mbox, name, digest)) == nil)
+		return;
+	if((flags = readfile(name, "/flags", nil)) == nil)
+		return;
+	free(m->flags);
+	m->flags = flags;
+	mesgmenureflag(mbox.w, m);
+}
+	
+
 extern int mesgsave(Message*, char*);
 void
 savemesg(char *box, char *name, char *digest)
@@ -361,6 +377,8 @@
 			newmesg(m->data, digest);
 		else if(strcmp(type, "delete") == 0)
 			delmesg(m->data, digest, 0);
+		else if(strcmp(type, "modify") == 0)
+			modmesg(m->data, digest);
 		else
 			fprint(2, "Mail: unknown plumb attribute %s\n", type);
 		plumbfree(m);
diff -r 7f3f8606fc12 sys/src/cmd/upas/fs/dat.h
--- a/sys/src/cmd/upas/fs/dat.h	Sun Dec 08 11:58:52 2019 -0800
+++ b/sys/src/cmd/upas/fs/dat.h	Sun Dec 08 11:59:39 2019 -0800
@@ -7,6 +7,7 @@
 	Cheader 	= 1<<2,
 	Cbody		= 1<<3,
 	Cnew		= 1<<4,
+	Cmod		= 1<<5,
 
 	/* encodings */
 	Enone=	0,
diff -r 7f3f8606fc12 sys/src/cmd/upas/fs/fs.c
--- a/sys/src/cmd/upas/fs/fs.c	Sun Dec 08 11:58:52 2019 -0800
+++ b/sys/src/cmd/upas/fs/fs.c	Sun Dec 08 11:59:39 2019 -0800
@@ -337,14 +337,15 @@
 		mboxfile = mbox;
 	}
 
-	if(mboxfile != nil)
-		if(err = newmbox(mboxfile, "mbox", 0, nil))
-			sysfatal("opening %s: %s", mboxfile, err);
 
 	switch(rfork(RFFDG|RFPROC|RFNAMEG|RFNOTEG|RFREND)){
 	case -1:
 		error("fork");
 	case 0:
+		print("child\n");
+		if(mboxfile != nil)
+			if(err = newmbox(mboxfile, "mbox", 0, nil))
+				sysfatal("opening %s: %s", mboxfile, err);
 		henter(PATH(0, Qtop), dirtab[Qctl],
 			(Qid){PATH(0, Qctl), 0, QTFILE}, nil, nil);
 		close(p[1]);
diff -r 7f3f8606fc12 sys/src/cmd/upas/fs/imap.c
--- a/sys/src/cmd/upas/fs/imap.c	Sun Dec 08 11:58:52 2019 -0800
+++ b/sys/src/cmd/upas/fs/imap.c	Sun Dec 08 11:59:39 2019 -0800
@@ -35,7 +35,7 @@
 	uvlong	uid;
 	ulong	sizes;
 	ulong	dates;
-	ulong	flags;
+	uint	flags;
 } Fetchi;
 
 typedef struct Imap Imap;
@@ -1006,6 +1006,8 @@
 			m->deleted = Disappear;
 			ll = &m->next;
 		}else{
+			if((m->flags & ~Frecent) != (f[i].flags & ~Frecent))
+				m->cstate |= Cmod;
 			m->flags = f[i].flags;
 			ll = &m->next;
 			i++;
diff -r 7f3f8606fc12 sys/src/cmd/upas/fs/mbox.c
--- a/sys/src/cmd/upas/fs/mbox.c	Sun Dec 08 11:58:52 2019 -0800
+++ b/sys/src/cmd/upas/fs/mbox.c	Sun Dec 08 11:59:39 2019 -0800
@@ -58,9 +58,6 @@
 static void delmessage(Mailbox*, Message*);
 static void mailplumb(Mailbox*, Message*);
 
-/*
- * do we want to plumb flag changes?
- */
 char*
 syncmbox(Mailbox *mb, int doplumb)
 {
@@ -90,16 +87,14 @@
 				cachehash(mb, m);
 				m->cstate |= Cnew;
 				n++;
-			} else if(!doplumb)
-				m->cstate &= ~Cnew;
-			if(m->cstate & Cnew){
-				if(ensurecache(mb, m) == 0){
-					if(doplumb)
-						mailplumb(mb, m);
+			}
+			if(doplumb){
+				if((m->cstate & Cnew) && ensurecache(mb, m) == 0)
 					msgdecref(mb, m);
-				}
-				m->cstate &= ~Cnew;
+				if(m->cstate & (Cnew|Cmod))
+					mailplumb(mb, m);
 			}
+			m->cstate &= ~(Cnew|Cmod);
 		}
 		if(m->cstate & Cidxstale)
 			y++;
@@ -1555,7 +1550,12 @@
 	a[ai-1].next = &a[ai];
 
 	a[++ai].name = "mailtype";
-	a[ai].value = !m->inmbox ? "delete": "new";
+	if(m->cstate & Cmod)
+		a[ai].value = "modify";
+	else if (!m->inmbox)
+		a[ai].value = "delete";
+	else
+		a[ai].value = "new";
 	a[ai-1].next = &a[ai];
 
 	snprint(date, sizeof date, "%Δ", m->fileid);



                 reply	other threads:[~2019-12-08 20:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=27DBD03EAF07864ED33411518EE16A58@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).