aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--filter/ChangeLog7
-rw-r--r--filter/filter-message-search.c47
-rw-r--r--filter/filtertypes.xml51
-rw-r--r--filter/libfilter-i18n.h2
4 files changed, 107 insertions, 0 deletions
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 <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).
+
2000-10-27 Jacob "Ulysses" Berkman <jacob@helixcode.com>
* 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 <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;
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})))
</code>
</option>
+ <option value="is">
+ <title>is</title>
+ <code>
+ (match-all (header-matches "From" ${sender}))
+ </code>
+ </option>
+ <option value="is not">
+ <title>is not</title>
+ <code>
+ (match-all (not (header-matches "From" ${sender})))
+ </code>
+ </option>
<option value="matches regex">
<title>matches regex</title>
<code>
@@ -50,6 +62,21 @@
(header-contains "Cc" ${recipient}))))
</code>
</option>
+ <option value="is">
+ <title>is</title>
+ <code>
+ (match-all (or (header-matches "To" ${recipient})
+ (header-matches "Cc" ${recipient})))
+ </code>
+ </option>
+ <option value="is not">
+ <title>is not</title>
+ <code>
+ (match-all (not (or
+ (header-matches "To" ${recipient})
+ (header-matches "Cc" ${recipient}))))
+ </code>
+ </option>
<option value="matches regex">
<title>matches regex</title>
<code>
@@ -84,6 +111,18 @@
(match-all (not (header-contains "Subject" ${subject})))
</code>
</option>
+ <option value="is">
+ <title>is</title>
+ <code>
+ (match-all (header-matches "Subject" ${subject}))
+ </code>
+ </option>
+ <option value="is not">
+ <title>is not</title>
+ <code>
+ (match-all (not (header-matches "Subject" ${subject}))
+ </code>
+ </option>
<option value="matches regex">
<title>matches regex</title>
<code>
@@ -116,6 +155,18 @@
(match-all (not (header-contains ${header-field} ${word})))
</code>
</option>
+ <option value="is">
+ <title>is</title>
+ <code>
+ (match-all (header-matches ${header-field} ${word}))
+ </code>
+ </option>
+ <option value="is not">
+ <title>is not</title>
+ <code>
+ (match-all (not (header-matches ${header-field} ${word}))
+ </code>
+ </option>
<option value="matches regex">
<title>matches regex</title>
<code>
diff --git a/filter/libfilter-i18n.h b/filter/libfilter-i18n.h
index f053dae7ec..9451d25ee5 100644
--- a/filter/libfilter-i18n.h
+++ b/filter/libfilter-i18n.h
@@ -23,11 +23,13 @@ char *s = N_("before");
char *s = N_("contains");
char *s = N_("does not contain");
char *s = N_("does not match regex");
+char *s = N_("does not match");
char *s = N_("is greater than");
char *s = N_("is less than");
char *s = N_("is not");
char *s = N_("is");
char *s = N_("matches regex");
+char *s = N_("matches");
char *s = N_("on or after");
char *s = N_("on or before");
char *s = N_("was after");