]> granicus.if.org Git - neomutt/commitdiff
Adds the '@' pattern modifier to limit matches to known aliases.
authorDavid Champion <dgc@bikeshed.us>
Thu, 17 Nov 2016 00:05:02 +0000 (16:05 -0800)
committerDavid Champion <dgc@bikeshed.us>
Thu, 17 Nov 2016 00:05:02 +0000 (16:05 -0800)
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
mutt.h
pattern.c

index fdd595265d57abe6a7d2c1218e4b6e7931bfa9f5..75034cd0a0954c9bf156a5597c79dc907e0f647a 100644 (file)
@@ -4359,6 +4359,29 @@ configuration command, preventing Mutt from recording the
 <command>macro</command>'s commands into its history.
 </para>
 
+<para>
+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.
+</para>
+
+<para>
+<screen>
+^@~C \.de$
+</screen>
+</para>
+
+<para>
+To match any defined alias, use a regular expression that matches any
+string.  This example matches messages whose senders are known aliases.
+</para>
+
+<para>
+<screen>
+@~f .
+</screen>
+</para>
+
 </sect3>
 
 </sect2>
diff --git a/mutt.h b/mutt.h
index 98660daeb8052f4542994147280332c9e77e36a3..6339613d6a46cbea4ac46438e88ce08ac6f5ac1a 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -860,6 +860,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;
index 1248e14efeab364de11c2bb6ed6a036eca948590..f1d46699b19a5d73da242b5594000fd9c8e86cb8 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -783,6 +783,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;
@@ -805,6 +806,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)
        {
@@ -830,6 +835,7 @@ pattern_t *mutt_pattern_comp (/* const */ char *s, int flags, BUFFER *err)
        implicit = 0;
        not = 0;
        alladdr = 0;
+       isalias = 0;
        break;
       case '%':
       case '=':
@@ -859,8 +865,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)
@@ -888,10 +896,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;
@@ -957,8 +967,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:
@@ -1010,8 +1022,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 */