Rocco Rutte:
authorpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Sun, 27 Feb 2005 01:01:21 +0000 (01:01 +0000)
committerpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Sun, 27 Feb 2005 01:01:21 +0000 (01:01 +0000)
added '~*' pattern as score on realname (email addr. and >=2 name fields; esp. for usenet)

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@95 e385b8ad-14ed-0310-8656-cc95a2468c6d

doc/manual.sgml.head
mutt.h
pattern.c

index abed2a6..52f624e 100644 (file)
@@ -1922,6 +1922,9 @@ messages:
 ~z [MIN]-[MAX]  messages with a size in the range MIN to MAX *)
 ~=             duplicated messages (see $duplicate_threads)
 ~$             unreferenced messages (requires threaded view)
+~*             ``From'' contains realname and (syntactically) valid
+               address (excluded are addresses matching against
+               alternates or any alias)
 </verb></tscreen>
 
 Where EXPR, USER, ID, and SUBJECT are 
diff --git a/mutt.h b/mutt.h
index fa33d31..0eb6139 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
  * Copyright (C) 2004 g10 Code GmbH
@@ -219,6 +218,7 @@ enum
   M_LIMIT,
   M_EXPIRED,
   M_SUPERSEDED,
+  M_REALNAME,
 
   /* actions for mutt_pattern_comp/mutt_pattern_exec */
   M_AND,
index a0457c9..e07a52c 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -91,6 +91,7 @@ Flags[] =
   { 'z', M_SIZE,               0,              eat_range },
   { '=', M_DUPLICATED,         0,              NULL },
   { '$', M_UNREFERENCED,       0,              NULL },
+  { '*', M_REALNAME,           0,              NULL },
   { 0 }
 };
 
@@ -952,6 +953,25 @@ static int match_user (int alladdr, ADDRESS *a1, ADDRESS *a2)
   return alladdr;
 }
 
+/* test if name is considered a real name, i.e. consists of at least 2
+ * space-separated words of which none may end in a dot
+ */
+static int valid_realname (const char* name)
+{
+  const char* p = name;
+  int ret = 0;
+  while (*p)
+  {
+    if (isspace (*p))
+      ret++;
+    else if (*p == '.')
+      /* skip abbr. parts of names (e.g. 'J. User') */
+      ret--;
+    p++;
+  }
+  return (ret >= 1);
+}
+
 /* flags
        M_MATCH_FULL_ADDRESS    match both personal and machine address */
 int
@@ -1060,6 +1080,18 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx,
       return (pat->not ^ (h->thread && h->thread->duplicate_thread));
     case M_UNREFERENCED:
       return (pat->not ^ (h->thread && !h->thread->child));
+    case M_REALNAME:
+      /* realname filter:
+       * we have a match if
+       * - From: matches $alternates
+       * - or we have an alias for current address
+       * - or From: contains valid email address _and_ name has >= 2 fields
+       */
+      return (pat->not ^ (h->env && h->env->from && (
+                            mutt_addr_is_user (h->env->from) ||
+                            (alias_reverse_lookup (h->env->from) != NULL) ||
+                            (h->env->from->personal && valid_realname (h->env->from->personal) && h->env->from->mailbox)
+                            )));
 #ifdef USE_NNTP
     case M_NEWSGROUPS:
       return (pat->not ^ (h->env->newsgroups && regexec (pat->rx, h->env->newsgroups, 0, NULL, 0) == 0));