upas/Mail: Add support for message filtering

This commit is contained in:
Ori Bernstein 2024-12-09 03:58:40 +00:00
parent aa1e68e9fe
commit af83b606f9
2 changed files with 41 additions and 4 deletions

View file

@ -101,13 +101,20 @@ are listed in
.IR upasfs (4)
.PD 0
.TP
.B Filter [pattern]
Shows only messages where the sender or subject match
the
.I pattern
regexp.
Filter without an argument resets the filtering,
showing all messages again.
.PD 0
.TP
.B Redraw
Redraws the contents of the mailbox.
.PP
The following text commands are recognized by the message
view:
.TP
.B Reply [all]
Replies to a message, quoting it.

View file

@ -31,6 +31,7 @@ char *listfmt = "%>48s\t<%f>";
Mesg dead = {.messageid="", .hash=42};
Reprog *mesgpat;
Reprog *filterpat;
int threadsort = 1;
int sender;
@ -575,13 +576,22 @@ fmtmesg(Biobuf *bp, char *fmt, Mesg *m, int depth)
Bputc(bp, '\n');
}
static int
matchfilter(Mesg *m)
{
if(filterpat == nil
|| regexec(filterpat, m->subject, nil, 0)
|| regexec(filterpat, m->from, nil, 0))
return 1;
return 0;
}
static void
showmesg(Biobuf *bfd, Mesg *m, int depth, int recurse)
{
int i;
if(!(m->state & Sdummy)){
if(!(m->state & Sdummy) && matchfilter(m)){
fmtmesg(bfd, listfmt, m, depth);
depth++;
}
@ -868,6 +878,26 @@ redraw(char **, int)
showlist();
}
static void
filter(char **filt, int nfilt)
{
if(nfilt > 1){
fprint(2, "filter: only one argument supported");
return;
}
free(filterpat);
filterpat = nil;
if(nfilt == 1){
filterpat = regcomp(filt[0]);
if(filterpat == nil){
fprint(2, "Filter: %r");
return;
}
}
fprint(mbox.addr, ",");
showlist();
}
static void
nextunread(char **, int)
{
@ -886,8 +916,8 @@ Fn mboxfn[] = {
{"Redraw", redraw},
{"Next", nextunread},
{"Mark", mbmark},
#ifdef NOTYET
{"Filter", filter},
#ifdef NOTYET
{"Get", mbrefresh},
#endif
{nil}