From e3566a474cdade04088e6789b694287e3f1072fb Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Fri, 27 Oct 2000 21:42:52 +0000 Subject: Add header-matches expressions ("is" / "is not"). 2000-10-27 Jeffrey Stedfast * filtertypes.xml: Add header-matches expressions ("is" / "is not"). * filter-message-search.c (header_matches): New callback to match headers exactly (aka strcmp rather than strstr). svn path=/trunk/; revision=6240 --- filter/ChangeLog | 7 ++++++ filter/filter-message-search.c | 47 ++++++++++++++++++++++++++++++++++++++ filter/filtertypes.xml | 51 ++++++++++++++++++++++++++++++++++++++++++ filter/libfilter-i18n.h | 2 ++ 4 files changed, 107 insertions(+) (limited to 'filter') diff --git a/filter/ChangeLog b/filter/ChangeLog index 0c62078bdd..8d2f6cdcf8 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,10 @@ +2000-10-27 Jeffrey Stedfast + + * filtertypes.xml: Add header-matches expressions ("is" / "is not"). + + * filter-message-search.c (header_matches): New callback to match + headers exactly (aka strcmp rather than strstr). + 2000-10-27 Jacob "Ulysses" Berkman * filter-driver.c (filter_driver_filter_mbox): divide before diff --git a/filter/filter-message-search.c b/filter/filter-message-search.c index a227af41c0..c8a85df71d 100644 --- a/filter/filter-message-search.c +++ b/filter/filter-message-search.c @@ -24,6 +24,7 @@ #include #include #include +#include typedef struct { CamelMimeMessage *message; @@ -34,6 +35,7 @@ typedef struct { /* ESExp callbacks */ static ESExpResult *header_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms); +static ESExpResult *header_matches (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms); static ESExpResult *header_regex (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms); static ESExpResult *match_all (struct _ESExp *f, int argc, struct _ESExpTerm **argv, FilterMessageSearch *fms); static ESExpResult *body_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms); @@ -57,6 +59,7 @@ static struct { { "body-contains", (ESExpFunc *) body_contains, 0 }, { "body-regex", (ESExpFunc *) body_regex, 0 }, { "header-contains", (ESExpFunc *) header_contains, 0 }, + { "header-matches", (ESExpFunc *) header_matches, 0 }, { "header-regex", (ESExpFunc *) header_regex, 0 }, { "user-tag", (ESExpFunc *) user_tag, 0 }, { "user-flag", (ESExpFunc *) user_flag, 0 }, @@ -92,6 +95,50 @@ header_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterM return r; } +static ESExpResult * +header_matches (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms) +{ + gboolean matched = FALSE; + ESExpResult *r; + + if (argc == 2) { + char *header = (argv[0])->value.string; + char *match = (argv[1])->value.string; + const char *contents; + + contents = camel_medium_get_header (CAMEL_MEDIUM (fms->message), header); + + if (contents) { + /* danw says to use search-engine style matching... + * This means that if the search match string is + * lowercase then compare case-insensitive else + * compare case-sensitive. */ + gboolean is_lowercase = TRUE; + char *c; + + for (c = match; *c; c++) { + if (isalpha (*c) && isupper (*c)) { + is_lowercase = FALSE; + break; + } + } + + if (is_lowercase) { + if (g_strcasecmp (contents, match)) + matched = TRUE; + } else { + if (strcmp (contents, match)) + matched = TRUE; + } + } + } + + r = e_sexp_result_new (ESEXP_RES_BOOL); + r->value.bool = matched; + + return r; +} + static ESExpResult * header_regex (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms) { diff --git a/filter/filtertypes.xml b/filter/filtertypes.xml index 6766f4bf3b..f1aa389ab1 100644 --- a/filter/filtertypes.xml +++ b/filter/filtertypes.xml @@ -16,6 +16,18 @@ (match-all (not (header-contains "From" ${sender}))) + + + + + + + +