ref: f7431283d906b1cd7e53eed47af055a5132bbfae
parent: 55af35eeeb3026ee9aba3658b7ba12d6ea3a5015
author: Ori Bernstein <[email protected]>
date: Mon Dec 9 07:46:27 EST 2019
upas/fs plumb flag changes. This patch makes 3 changes: - 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.
--- a/sys/src/cmd/faces/plumb.c
+++ b/sys/src/cmd/faces/plumb.c
@@ -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;
--- a/sys/src/cmd/upas/Mail/dat.h
+++ b/sys/src/cmd/upas/Mail/dat.h
@@ -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*);
--- a/sys/src/cmd/upas/Mail/mail.c
+++ b/sys/src/cmd/upas/Mail/mail.c
@@ -189,7 +189,7 @@
wbox = newwindow();
winname(wbox, mbox.name);
- wintagwrite(wbox, "Put Mail Delmesg Save ", 3+1+4+1+7+1+4+1);
+ wintagwrite(wbox, "Put Mail Delmesg Save Next ", 3+1+4+1+7+1+4+1+4+1);
threadcreate(mainctl, wbox, STACK);
fmtstrinit(&fmt);
@@ -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);
@@ -512,6 +530,11 @@
free(s);
free(targs);
return 1;
+ }
+ if(strcmp(args[0], "Next") == 0){
+ ctlprint(w->ctl, "addr=dot\n");
+ winselect(w, "/^[0-9]*\\/ \\[\\*.*(\\n(\t.*)*)/", 1);
+ ctlprint(w->ctl, "show\n");
}
return 0;
}
--- a/sys/src/cmd/upas/fs/dat.h
+++ b/sys/src/cmd/upas/fs/dat.h
@@ -7,6 +7,7 @@
Cheader = 1<<2,
Cbody = 1<<3,
Cnew = 1<<4,
+ Cmod = 1<<5,
/* encodings */
Enone= 0,
--- a/sys/src/cmd/upas/fs/imap.c
+++ b/sys/src/cmd/upas/fs/imap.c
@@ -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++;
--- a/sys/src/cmd/upas/fs/mbox.c
+++ b/sys/src/cmd/upas/fs/mbox.c
@@ -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,13 @@
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);
- msgdecref(mb, m);
- }
- m->cstate &= ~Cnew;
}
+ if((m->cstate & (Cnew|Cmod)) && ensurecache(mb, m) == 0){
+ if(doplumb)
+ mailplumb(mb, m);
+ msgdecref(mb, m);
+ }
+ m->cstate &= ~(Cnew|Cmod);
}
if(m->cstate & Cidxstale)
y++;
@@ -1555,7 +1549,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);