show and update flags in acme mail

now, it's possible to tell whether you've read or replied
to a message.
This commit is contained in:
Ori Bernstein 2019-12-01 17:14:13 -08:00
parent 84c4c81cee
commit 3889b249d4
3 changed files with 66 additions and 10 deletions

View file

@ -49,6 +49,7 @@ struct Message
int ctlfd;
char *name;
char *replyname;
char *replydigest;
uchar opened;
uchar dirty;
uchar isreply;
@ -70,11 +71,12 @@ struct Message
char *disposition;
char *filename;
char *digest;
char *flags;
Message *next; /* next in this mailbox */
Message *prev; /* prev in this mailbox */
Message *head; /* first subpart */
Message *tail; /* last subpart */
Message *tail; /* last subpart */
};
enum
@ -123,6 +125,7 @@ extern int write2(int, int, char*, int, int);
extern int mesgadd(Message*, char*, Dir*, char*);
extern void mesgmenu(Window*, Message*);
extern void mesgmenunew(Window*, Message*);
extern void mesgmenureflag(Window*, Message*);
extern int mesgopen(Message*, char*, char*, Message*, int, char*);
extern void mesgctl(void*);
extern void mesgsend(Message*);
@ -146,6 +149,7 @@ extern char* eappend(char*, char*, char*);
extern void error(char*, ...);
extern int tokenizec(char*, char**, int, char*);
extern void execproc(void*);
extern void setflags(Message*, char *);
#pragma varargck argpos error 1
#pragma varargck argpos ctlprint 2

View file

@ -132,7 +132,7 @@ loadinfo(Message *m, char *dir)
/* m->messageid = */ free(line(p, &p));
/* m->lines = */ free(line(p, &p));
/* m->size = */ free(line(p, &p));
/* m->flags = */ free(line(p, &p));
m->flags = line(p, &p);
/* m->fileid = */ free(line(p, &p));
m->fromcolon = fc(m, line(p, &p));
@ -308,14 +308,36 @@ writefile(char *dir, char *name, char *s)
return s == e? 0: -1;
}
void
setflags(Message *m, char *f)
{
char *t;
char *flgchar = "aDdfrsS";
char *t, *p;
int rm;
t = smprint("%s/%s", mbox.name, m->name);
writefile(t, "flags", f);
free(t);
for(; *f; f++){
rm = 0;
if(*f == '-'){
rm = 1;
f++;
}
if((p = strchr(flgchar, *f)) != nil)
m->flags[p - flgchar] = rm ? '-' : *f;
}
}
void
fmtflags(char *b, char *flg)
{
*b++ = '[';
*b++ = (strchr(flg, 's') == nil) ? '*' : ' '; /* unread */
*b++ = (strchr(flg, 'a') == nil) ? ' ' : 'R'; /* answered */
*b++ = ']';
*b = '\0';
}
char*
@ -324,13 +346,14 @@ info(Message *m, int ind, int ogf)
char *i;
int j, len, lens;
char *p;
char fmt[80], s[80];
char fmt[80], s[80], flg[16];
if (ogf)
p=m->to;
else
p=m->fromcolon;
fmtflags(flg, m->flags);
if(ind==0 && altmenu){
len = 12;
lens = 20;
@ -369,6 +392,7 @@ info(Message *m, int ind, int ogf)
}
i = estrdup("");
i = eappend(i, " ", flg);
i = eappend(i, "\t", p);
i = egrow(i, "\t", stripdate(m->date));
if(ind == 0){
@ -537,6 +561,24 @@ mesgmenudel(Window *w, Message *mbox, Message *m)
m->deleted = 1;
}
void
mesgmenureflag(Window *w, Message *m)
{
char *buf, flg[16];
fmtflags(flg, m->flags);
buf = name2regexp(deletedrx01, m->name);
strcat(buf, "+/\\[[^\\]]*\\]/");
if(w->data < 0)
w->data = winopenfile(w, "data");
if(winselect(w, buf, 1))
write(w->data, flg, strlen(flg));
free(buf);
close(w->data);
w->data = -1;
}
void
mesgmenumark(Window *w, char *which, char *mark)
{
@ -570,6 +612,7 @@ mesgfreeparts(Message *m)
free(m->type);
free(m->disposition);
free(m->filename);
free(m->flags);
free(m->digest);
}
@ -1312,6 +1355,7 @@ mesgopen(Message *mbox, char *dir, char *s, Message *mesg, int plumbed, char *di
winclean(m->w);
m->opened = 1;
setflags(m, "s");
mesgmenureflag(mbox->w, m);
if(ndirelem == 1){
free(u);
return 1;

View file

@ -77,8 +77,10 @@ mkreply(Message *m, char *label, char *to, Plumbattr *attr, char *quotetext)
quotereply = (label[0] == 'Q');
r = emalloc(sizeof(Message));
r->isreply = 1;
if(m != nil)
if(m != nil){
r->replyname = estrdup(m->name);
r->replydigest = estrdup(m->digest);
}
r->next = replies.head;
r->prev = nil;
if(replies.head != nil)
@ -184,7 +186,7 @@ buildargv(char **inargv, char *argv[NARGS+1], char args[NARGCHAR])
void
execproc(void *v)
{
struct Exec *e;
Exec *e;
int p[2], q[2];
char *prog;
char *argv[NARGS+1], args[NARGCHAR];
@ -382,8 +384,9 @@ mesgsend(Message *m)
{
char *s, *body, *to;
int i, j, h, n, natt, p[2];
struct Exec *e;
Exec *e;
Channel *sync;
Message *r;
int first, nfld, delit, ofd;
char *copy, *fld[100], *now;
@ -479,7 +482,7 @@ mesgsend(Message *m)
fprint(ofd, "Content-Transfer-Encoding: 8bit\n");
}
e = emalloc(sizeof(struct Exec));
e = emalloc(sizeof(Exec));
if(pipe(p) < 0)
error("can't create pipe: %r");
e->p[0] = p[0];
@ -553,8 +556,13 @@ mesgsend(Message *m)
close(p[1]);
free(body);
if(m->replyname != nil)
mesgmenumark(mbox.w, m->replyname, "\t[replied]");
print("replyname: %s, replydigest=%s\n", m->replyname, m->replydigest);
if(m->replyname){
if((r = mesglookup(&mbox, m->replyname, m->replydigest)) != nil){
setflags(r, "a");
mesgmenureflag(mbox.w, r);
}
}
if(m->name[0] == '/')
s = estrdup(m->name);
else