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) .IR upasfs (4)
.PD 0 .PD 0
.TP .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 .B Redraw
Redraws the contents of the mailbox. Redraws the contents of the mailbox.
.PP .PP
The following text commands are recognized by the message The following text commands are recognized by the message
view: view:
.TP .TP
.B Reply [all] .B Reply [all]
Replies to a message, quoting it. Replies to a message, quoting it.

View file

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