aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-message-search.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-10-28 05:42:52 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-10-28 05:42:52 +0800
commite3566a474cdade04088e6789b694287e3f1072fb (patch)
treebae90c5ebdc2d62ff4e31883efdd00c52a255d27 /filter/filter-message-search.c
parent7b8d4345fe3671e0d6fe0dab23ba1212d564a172 (diff)
downloadgsoc2013-evolution-e3566a474cdade04088e6789b694287e3f1072fb.tar
gsoc2013-evolution-e3566a474cdade04088e6789b694287e3f1072fb.tar.gz
gsoc2013-evolution-e3566a474cdade04088e6789b694287e3f1072fb.tar.bz2
gsoc2013-evolution-e3566a474cdade04088e6789b694287e3f1072fb.tar.lz
gsoc2013-evolution-e3566a474cdade04088e6789b694287e3f1072fb.tar.xz
gsoc2013-evolution-e3566a474cdade04088e6789b694287e3f1072fb.tar.zst
gsoc2013-evolution-e3566a474cdade04088e6789b694287e3f1072fb.zip
Add header-matches expressions ("is" / "is not").
2000-10-27 Jeffrey Stedfast <fejj@helixcode.com> * 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
Diffstat (limited to 'filter/filter-message-search.c')
-rw-r--r--filter/filter-message-search.c47
1 files changed, 47 insertions, 0 deletions
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 <e-util/e-sexp.h>
#include <regex.h>
#include <string.h>
+#include <ctype.h>
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 },
@@ -93,6 +96,50 @@ header_contains (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterM
}
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)
{
gboolean matched = FALSE;