Just a little something I've had in my local branch for
some 15 years :)
Rediscovered that I never submitted it when I was checking
that the xoauth branch still works (clean merge, btw, except
one little Makefile.am conflict).
If this passes muster, would someone else mind submitting?
I unfortunately don't have access right now to the machine
that has my Savannah ssh key...
Thanks.
diff --git a/man/pick.man b/man/pick.man
index 000da22..9d7cdcf 100644
--- a/man/pick.man
+++ b/man/pick.man
@@ -10,6 +10,8 @@ pick \- search for messages by content
.B pick
.RI [ +folder ]
.RI [ msgs ]
+.RB [ \-reverse
+\&...]
.RB [ \-and
\&...]
.RB [ \-or
@@ -177,6 +179,20 @@ will
also honor a specification of the form \*(lq\-dd\*(rq, which means
\*(lqdd days ago\*(rq.
.PP
+Use the
+.BR \-reverse
+switch to make
+.B pick
+find matching messages in reverse order, working from the highest message
+number down to the lowest. This can be useful in for searching recent
+messages in large folders, for example,
+.PP
+.RS 5
+.nf
+pick\0\-reverse\0\-from\0frated\0|\0xargs\0\-n1\0scan
+.fi
+.RE
+.PP
.B Pick
supports complex boolean operations on the searching primitives
with the
diff --git a/test/pick/test-pick b/test/pick/test-pick
index 858d8e7..ca19bb8 100755
--- a/test/pick/test-pick
+++ b/test/pick/test-pick
@@ -49,6 +49,12 @@ run_test 'pick -not -subject message.8 last:5' '7
10
11'
+# Test -reverse.
+run_test 'pick -reverse -not -subject message.8 last:5' '11
+10
+9
+7'
+
# Test -lbrace, -rbrace.
run_test 'pick -subject message.12 -and -subject message.3 -or -from Test4' '4'
run_test 'pick -subject message.12 -and -lbrace -subject message.3 -rbrace' \
diff --git a/uip/pick.c b/uip/pick.c
index d29799b..fba190a 100644
--- a/uip/pick.c
+++ b/uip/pick.c
@@ -13,6 +13,7 @@
#include <h/utils.h>
#define PICK_SWITCHES \
+ X("reverse", 0, REVSW) \
X("and", 0, ANDSW) \
X("or", 0, ORSW) \
X("not", 0, NOTSW) \
@@ -67,6 +68,7 @@ main (int argc, char **argv)
struct msgs *mp, *mp2;
register FILE *fp;
int debug = 0;
+ int reverse = 0;
if (nmh_init(argv[0], 1)) { return 1; }
@@ -104,6 +106,10 @@ main (int argc, char **argv)
listsw = 0; /* HACK */
done (0);
+ case REVSW:
+ reverse = 1;
+ continue;
+
case CCSW:
case DATESW:
case FROMSW:
@@ -231,7 +237,9 @@ main (int argc, char **argv)
* match. If there is NOT a match, then add it to a list to
* remove from the final sequence (it will make sense later)
*/
- for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
+ for (msgnum = reverse ? mp->hghsel : mp->lowsel;
+ reverse ? msgnum >= mp->lowsel : msgnum <= mp->hghsel;
+ msgnum += reverse ? -1 : 1) {
if (is_selected (mp, msgnum)) {
if ((fp = fopen (cp = m_name (msgnum), "r")) == NULL)
admonish (cp, "unable to read message");
_______________________________________________
Nmh-workers mailing list
Nmh-workers(_at_)nongnu(_dot_)org
https://lists.nongnu.org/mailman/listinfo/nmh-workers