diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2010-02-10 09:31:53 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2010-02-10 09:31:53 +0000 |
commit | 3f9703a3fd35f7d8b835c62869c0db74bd213e2f (patch) | |
tree | acbaf735dc3a1d98d0322f6a5634ea51c7c1b707 /libsylph | |
parent | 6ab1d3cf538aa7f6c5385f7010e9a2d7e71b8dc0 (diff) |
added a new filter match type: is (not) in addressbook.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2461 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r-- | libsylph/filter.c | 77 | ||||
-rw-r--r-- | libsylph/filter.h | 11 |
2 files changed, 85 insertions, 3 deletions
diff --git a/libsylph/filter.c b/libsylph/filter.c index 182fbb27..35bb9369 100644 --- a/libsylph/filter.c +++ b/libsylph/filter.c @@ -54,12 +54,18 @@ typedef enum FLT_O_REGEX = 1 << 2 } FilterOldFlag; +FilterInAddressBookFunc default_addrbook_func = NULL; + static gboolean filter_match_cond (FilterCond *cond, MsgInfo *msginfo, GSList *hlist, FilterInfo *fltinfo); static gboolean filter_match_header_cond(FilterCond *cond, GSList *hlist); +static gboolean filter_match_in_addressbook + (FilterCond *cond, + GSList *hlist, + FilterInfo *fltinfo); static void filter_cond_free (FilterCond *cond); static void filter_action_free (FilterAction *action); @@ -388,9 +394,17 @@ static gboolean filter_match_cond(FilterCond *cond, MsgInfo *msginfo, switch (cond->type) { case FLT_COND_HEADER: + if (cond->match_type == FLT_IN_ADDRESSBOOK) + return filter_match_in_addressbook(cond, hlist, fltinfo); + else + return filter_match_header_cond(cond, hlist); case FLT_COND_ANY_HEADER: - case FLT_COND_TO_OR_CC: return filter_match_header_cond(cond, hlist); + case FLT_COND_TO_OR_CC: + if (cond->match_type == FLT_IN_ADDRESSBOOK) + return filter_match_in_addressbook(cond, hlist, fltinfo); + else + return filter_match_header_cond(cond, hlist); case FLT_COND_BODY: matched = procmime_find_string(msginfo, cond->str_value, cond->match_func); @@ -490,6 +504,45 @@ static gboolean filter_match_header_cond(FilterCond *cond, GSList *hlist) return matched; } +static gboolean filter_match_in_addressbook(FilterCond *cond, GSList *hlist, + FilterInfo *fltinfo) +{ + gboolean matched = FALSE; + GSList *cur; + Header *header; + + if (!default_addrbook_func) + return FALSE; + if (cond->type != FLT_COND_HEADER && cond->type != FLT_COND_TO_OR_CC) + return FALSE; + + for (cur = hlist; cur != NULL; cur = cur->next) { + header = (Header *)cur->data; + + if (cond->type == FLT_COND_HEADER) { + if (!g_ascii_strcasecmp + (header->name, cond->header_name)) { + if (default_addrbook_func(header->body)) + matched = TRUE; + } + } else if (cond->type == FLT_COND_TO_OR_CC) { + if (!g_ascii_strcasecmp(header->name, "To") || + !g_ascii_strcasecmp(header->name, "Cc")) { + if (default_addrbook_func(header->body)) + matched = TRUE; + } + } + + if (matched == TRUE) + break; + } + + if (FLT_IS_NOT_MATCH(cond->match_flag)) + matched = !matched; + + return matched; +} + gboolean filter_rule_requires_full_headers(FilterRule *rule) { GSList *cur; @@ -856,6 +909,11 @@ void filter_write_file(GSList *list, const gchar *file) FLT_IS_NOT_MATCH(cond->match_flag) ? "not-regex" : "regex"); break; + case FLT_IN_ADDRESSBOOK: + strcpy(match_type, + FLT_IS_NOT_MATCH(cond->match_flag) + ? "not-in-addressbook" : "in-addressbook"); + break; default: match_type[0] = '\0'; break; @@ -1206,6 +1264,16 @@ FilterRule *filter_read_str(const gchar *str) return rule; } +void filter_set_addressbook_func(FilterInAddressBookFunc func) +{ + default_addrbook_func = func; +} + +FilterInAddressBookFunc filter_get_addressbook_func(void) +{ + return default_addrbook_func; +} + FilterRule *filter_rule_new(const gchar *name, FilterBoolOp bool_op, GSList *cond_list, GSList *action_list) { @@ -1253,6 +1321,8 @@ FilterCond *filter_cond_new(FilterCondType type, cond->match_func = str_find_equal; else cond->match_func = str_case_find_equal; + } else if (match_type == FLT_IN_ADDRESSBOOK) { + cond->match_func = str_case_find_equal; } else { if (FLT_IS_CASE_SENS(match_flag)) cond->match_func = str_find; @@ -1421,6 +1491,11 @@ void filter_rule_match_type_str_to_enum(const gchar *match_type, } else if (!strcmp(match_type, "not-regex")) { *type = FLT_REGEX; *flag = FLT_NOT_MATCH; + } else if (!strcmp(match_type, "in-addressbook")) { + *type = FLT_IN_ADDRESSBOOK; + } else if (!strcmp(match_type, "not-in-addressbook")) { + *type = FLT_IN_ADDRESSBOOK; + *flag = FLT_NOT_MATCH; } else if (!strcmp(match_type, "gt")) { } else if (!strcmp(match_type, "lt")) { *flag = FLT_NOT_MATCH; diff --git a/libsylph/filter.h b/libsylph/filter.h index 132810f5..35c43c70 100644 --- a/libsylph/filter.h +++ b/libsylph/filter.h @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2007 Hiroyuki Yamamoto + * Copyright (C) 1999-2010 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -58,7 +58,8 @@ typedef enum { FLT_CONTAIN, FLT_EQUAL, - FLT_REGEX + FLT_REGEX, + FLT_IN_ADDRESSBOOK } FilterMatchType; typedef enum @@ -110,6 +111,8 @@ typedef enum #define FLT_IS_NOT_MATCH(flag) ((flag & FLT_NOT_MATCH) != 0) #define FLT_IS_CASE_SENS(flag) ((flag & FLT_CASE_SENS) != 0) +typedef gboolean (*FilterInAddressBookFunc) (const gchar *address); + struct _FilterCond { FilterCondType type; @@ -193,6 +196,10 @@ void filter_write_config (void); gchar *filter_get_str (FilterRule *rule); FilterRule *filter_read_str (const gchar *str); +void filter_set_addressbook_func (FilterInAddressBookFunc func); +FilterInAddressBookFunc filter_get_addressbook_func + (void); + FilterRule *filter_rule_new (const gchar *name, FilterBoolOp bool_op, GSList *cond_list, |