ref: 7fbd55cb6aaea2d86de69e7342bc33483037d188
parent: 0d5c37265c4c473970b6dbe75ded11d823669939
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Dec 8 22:58:40 EST 2024
upas/Mail: Add support for message filtering
--- a/sys/man/1/acmemail
+++ b/sys/man/1/acmemail
@@ -101,13 +101,20 @@
.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.
--- a/sys/src/cmd/upas/Mail/mbox.c
+++ b/sys/src/cmd/upas/Mail/mbox.c
@@ -31,6 +31,7 @@
Mesg dead = {.messageid="", .hash=42};Reprog *mesgpat;
+Reprog *filterpat;
int threadsort = 1;
int sender;
@@ -575,6 +576,15 @@
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)
@@ -581,7 +591,7 @@
{int i;
- if(!(m->state & Sdummy)){+ if(!(m->state & Sdummy) && matchfilter(m)){fmtmesg(bfd, listfmt, m, depth);
depth++;
}
@@ -869,6 +879,26 @@
}
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)
{fprint(mbox.ctl, "addr=dot\n");
@@ -886,8 +916,8 @@
{"Redraw", redraw}, {"Next", nextunread}, {"Mark", mbmark},-#ifdef NOTYET
{"Filter", filter},+#ifdef NOTYET
{"Get", mbrefresh},#endif
{nil}--
⑨