From 3d8d72a92d3892157a865900fcc38065bde5e83a Mon Sep 17 00:00:00 2001 From: David Champion Date: Wed, 16 Nov 2016 16:05:02 -0800 Subject: [PATCH] Adds the '@' pattern modifier to limit matches to known aliases. Example: ~f joe matches messages from joe. @~f joe matches messages from any joe who is defined as an alias. Pushed by Kevin McCarthy with two minor cosmetic fixes. --- doc/manual.xml.head | 23 +++++++++++++++++++++++ mutt.h | 1 + pattern.c | 18 ++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/doc/manual.xml.head b/doc/manual.xml.head index cf336efdd..8b5fabdab 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -5018,6 +5018,29 @@ configuration command, preventing Mutt from recording the macro's commands into its history. + +You can restrict address pattern matching to aliases that you have +defined with the "@" modifier. This example matches messages whose +recipients are all from Germany, and who are known to your alias list. + + + + +^@~C \.de$ + + + + +To match any defined alias, use a regular expression that matches any +string. This example matches messages whose senders are known aliases. + + + + +@~f . + + + diff --git a/mutt.h b/mutt.h index c3d001d74..4e31f56ae 100644 --- a/mutt.h +++ b/mutt.h @@ -945,6 +945,7 @@ typedef struct pattern_t unsigned int stringmatch : 1; unsigned int groupmatch : 1; unsigned int ign_case : 1; /* ignore case for local stringmatch searches */ + unsigned int isalias : 1; int min; int max; struct pattern_t *next; diff --git a/pattern.c b/pattern.c index c225377d3..7750151a9 100644 --- a/pattern.c +++ b/pattern.c @@ -834,6 +834,7 @@ pattern_t *mutt_pattern_comp (/* const */ char *s, int flags, BUFFER *err) int alladdr = 0; int or = 0; int implicit = 1; /* used to detect logical AND operator */ + int isalias = 0; const struct pattern_flags *entry; char *p; char *buf; @@ -856,6 +857,10 @@ pattern_t *mutt_pattern_comp (/* const */ char *s, int flags, BUFFER *err) ps.dptr++; not = !not; break; + case '@': + ps.dptr++; + isalias = !isalias; + break; case '|': if (!or) { @@ -881,6 +886,7 @@ pattern_t *mutt_pattern_comp (/* const */ char *s, int flags, BUFFER *err) implicit = 0; not = 0; alladdr = 0; + isalias = 0; break; case '%': case '=': @@ -910,8 +916,10 @@ pattern_t *mutt_pattern_comp (/* const */ char *s, int flags, BUFFER *err) last = tmp; tmp->not ^= not; tmp->alladdr |= alladdr; + tmp->isalias |= isalias; not = 0; alladdr = 0; + isalias = 0; /* compile the sub-expression */ buf = mutt_substrdup (ps.dptr + 1, p); if ((tmp2 = mutt_pattern_comp (buf, flags, err)) == NULL) @@ -939,10 +947,12 @@ pattern_t *mutt_pattern_comp (/* const */ char *s, int flags, BUFFER *err) tmp = new_pattern (); tmp->not = not; tmp->alladdr = alladdr; + tmp->isalias = isalias; tmp->stringmatch = (*ps.dptr == '=') ? 1 : 0; tmp->groupmatch = (*ps.dptr == '%') ? 1 : 0; not = 0; alladdr = 0; + isalias = 0; if (last) last->next = tmp; @@ -1008,8 +1018,10 @@ pattern_t *mutt_pattern_comp (/* const */ char *s, int flags, BUFFER *err) last = tmp; tmp->not ^= not; tmp->alladdr |= alladdr; + tmp->isalias |= isalias; not = 0; alladdr = 0; + isalias = 0; ps.dptr = p + 1; /* restore location */ break; default: @@ -1061,8 +1073,10 @@ static int match_adrlist (pattern_t *pat, int match_personal, int n, ...) { for (a = va_arg (ap, ADDRESS *) ; a ; a = a->next) { - if (pat->alladdr ^ ((a->mailbox && patmatch (pat, a->mailbox) == 0) || - (match_personal && a->personal && patmatch (pat, a->personal) == 0))) + if (pat->alladdr ^ + ((!pat->isalias || alias_reverse_lookup (a)) && + ((a->mailbox && !patmatch (pat, a->mailbox)) || + (match_personal && a->personal && !patmatch (pat, a->personal) )))) { va_end (ap); return (! pat->alladdr); /* Found match, or non-match if alladdr */ -- 2.49.0