diff --git a/sys/man/1/acmemail b/sys/man/1/acmemail index 16d5373bd..2d3626962 100644 --- a/sys/man/1/acmemail +++ b/sys/man/1/acmemail @@ -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. diff --git a/sys/src/cmd/upas/Mail/mbox.c b/sys/src/cmd/upas/Mail/mbox.c index a04db68e5..5c5dd8bd4 100644 --- a/sys/src/cmd/upas/Mail/mbox.c +++ b/sys/src/cmd/upas/Mail/mbox.c @@ -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}