changeset: 7100:428e36fb2262 user: Kevin McCarthy <ke...@8t8.us> date: Wed Jul 05 19:09:51 2017 -0700 link: http://dev.mutt.org/hg/mutt/rev/428e36fb2262
Add ~<() and ~>() immediate parent/children patterns. (closes #3144) Thanks to Jeremie Le Hen for the original patch, and for his persistence in getting this feature merged. diffs (122 lines): diff -r c87d2a88308a -r 428e36fb2262 doc/manual.xml.head --- a/doc/manual.xml.head Mon Jul 03 19:22:25 2017 -0700 +++ b/doc/manual.xml.head Wed Jul 05 19:09:51 2017 -0700 @@ -5213,6 +5213,12 @@ <row><entry>~(<emphasis>PATTERN</emphasis>)</entry><entry>messages in threads containing messages matching <emphasis>PATTERN</emphasis>, e.g. all threads containing messages from you: ~(~P)</entry></row> +<row><entry>~<(<emphasis>PATTERN</emphasis>)</entry><entry>messages +whose immediate parent matches <emphasis>PATTERN</emphasis>, +e.g. replies to your messages: ~<(~P)</entry></row> +<row><entry>~>(<emphasis>PATTERN</emphasis>)</entry><entry>messages +having an immediate child matching <emphasis>PATTERN</emphasis>, +e.g. messages you replied to: ~>(~P)</entry></row> </tbody> </tgroup> </table> diff -r c87d2a88308a -r 428e36fb2262 doc/muttrc.man.head --- a/doc/muttrc.man.head Mon Jul 03 19:22:25 2017 -0700 +++ b/doc/muttrc.man.head Wed Jul 05 19:09:51 2017 -0700 @@ -622,6 +622,12 @@ .TP ~(PATTERN) messages in threads containing messages matching a certain pattern, e.g. all threads containing messages from you: ~(~P) +.TP +~<(PATTERN) +messages whose immediate parent matches PATTERN, e.g. replies to your messages: ~<(~P) +.TP +~>(PATTERN) +messages having an immediate child matching PATTERN, e.g. messages you replied to: ~>(~P) .PD 1 .DT .PP diff -r c87d2a88308a -r 428e36fb2262 mutt.h --- a/mutt.h Mon Jul 03 19:22:25 2017 -0700 +++ b/mutt.h Wed Jul 05 19:09:51 2017 -0700 @@ -206,6 +206,8 @@ MUTT_AND, MUTT_OR, MUTT_THREAD, + MUTT_PARENT, + MUTT_CHILDREN, MUTT_TO, MUTT_CC, MUTT_COLLAPSED, diff -r c87d2a88308a -r 428e36fb2262 pattern.c --- a/pattern.c Mon Jul 03 19:22:25 2017 -0700 +++ b/pattern.c Wed Jul 05 19:09:51 2017 -0700 @@ -784,6 +784,7 @@ int or = 0; int implicit = 1; /* used to detect logical AND operator */ int isalias = 0; + short thread_op; const struct pattern_flags *entry; char *p; char *buf; @@ -846,9 +847,18 @@ mutt_pattern_free (&curlist); return NULL; } + thread_op = 0; if (*(ps.dptr + 1) == '(') + thread_op = MUTT_THREAD; + else if ((*(ps.dptr + 1) == '<') && (*(ps.dptr + 2) == '(')) + thread_op = MUTT_PARENT; + else if ((*(ps.dptr + 1) == '>') && (*(ps.dptr + 2) == '(')) + thread_op = MUTT_CHILDREN; + if (thread_op) { - ps.dptr ++; /* skip ~ */ + ps.dptr++; /* skip ~ */ + if (thread_op == MUTT_PARENT || thread_op == MUTT_CHILDREN) + ps.dptr++; p = find_matching_paren (ps.dptr + 1); if (*p != ')') { @@ -857,7 +867,7 @@ return NULL; } tmp = new_pattern (); - tmp->op = MUTT_THREAD; + tmp->op = thread_op; if (last) last->next = tmp; else @@ -1108,6 +1118,26 @@ return 0; } +static int match_threadparent(struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx, THREAD *t) +{ + if (!t || !t->parent || !t->parent->message) + return 0; + + return mutt_pattern_exec(pat, flags, ctx, t->parent->message, NULL); +} + +static int match_threadchildren(struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx, THREAD *t) +{ + if (!t || !t->child) + return 0; + + for (t = t->child; t; t = t->next) + if (t->message && mutt_pattern_exec(pat, flags, ctx, t->message, NULL)) + return 1; + + return 0; +} + /* Sets a value in the pattern_cache_t cache entry. * Normalizes the "true" value to 2. */ @@ -1148,6 +1178,10 @@ return (pat->not ^ (perform_or (pat->child, flags, ctx, h, cache) > 0)); case MUTT_THREAD: return (pat->not ^ match_threadcomplete(pat->child, flags, ctx, h->thread, 1, 1, 1, 1)); + case MUTT_PARENT: + return (pat->not ^ match_threadparent(pat->child, flags, ctx, h->thread)); + case MUTT_CHILDREN: + return (pat->not ^ match_threadchildren(pat->child, flags, ctx, h->thread)); case MUTT_ALL: return (!pat->not); case MUTT_EXPIRED: