From: pdmef Date: Sun, 27 Feb 2005 01:01:21 +0000 (+0000) Subject: Rocco Rutte: X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=6c3098ee86b61b0f3cbc269496e3d35cd24b6f7a;hp=be99cd72fc79e2f10aec2b06d62abb16c16aa34d Rocco Rutte: 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 --- diff --git a/doc/manual.sgml.head b/doc/manual.sgml.head index abed2a6..52f624e 100644 --- a/doc/manual.sgml.head +++ b/doc/manual.sgml.head @@ -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) Where EXPR, USER, ID, and SUBJECT are diff --git a/mutt.h b/mutt.h index fa33d31..0eb6139 100644 --- a/mutt.h +++ b/mutt.h @@ -1,4 +1,3 @@ - /* * Copyright (C) 1996-2002 Michael R. Elkins * 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, diff --git a/pattern.c b/pattern.c index a0457c9..e07a52c 100644 --- 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));