aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-message-search.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-11-28 06:23:33 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-11-28 06:23:33 +0800
commitdce674fa1a19593e8b9b3b2ddbe5524f9cc54714 (patch)
tree2452242615a527700c376f3b7bfc2c650b548710 /filter/filter-message-search.c
parent7a6e3e892c2dc5239c4921ad585ffd78895ae3b5 (diff)
downloadgsoc2013-evolution-dce674fa1a19593e8b9b3b2ddbe5524f9cc54714.tar
gsoc2013-evolution-dce674fa1a19593e8b9b3b2ddbe5524f9cc54714.tar.gz
gsoc2013-evolution-dce674fa1a19593e8b9b3b2ddbe5524f9cc54714.tar.bz2
gsoc2013-evolution-dce674fa1a19593e8b9b3b2ddbe5524f9cc54714.tar.lz
gsoc2013-evolution-dce674fa1a19593e8b9b3b2ddbe5524f9cc54714.tar.xz
gsoc2013-evolution-dce674fa1a19593e8b9b3b2ddbe5524f9cc54714.tar.zst
gsoc2013-evolution-dce674fa1a19593e8b9b3b2ddbe5524f9cc54714.zip
Moved the regex filter rule around - we've changed the format a bit.
2000-11-27 Jeffrey Stedfast <fejj@helixcode.com> * filtertypes.xml: Moved the regex filter rule around - we've changed the format a bit. * filter-option.c (option_activate): Removed. (get_widget): Don't connect the activate signal. * filter-folder.c (validate): Updated. * filter-datespec.c (validate): Updated. * filter-part.c (filter_part_validate): Updated. * filter-input.c (validate): Check the filter-input type - if it's of type "regex", then check for regex validity. * filter-element.c (filter_element_validate): No longer takes a gpointer argument. (filter_element_new_type_name): Allow type "regex" and create a new filter-input with type "regex". 2000-11-24 Michael Meeks <michael@helixcode.com> * filter-message-search.c (get_full_header): impl. (header_full_regex): use it. 2000-11-23 Michael Meeks <michael@helixcode.com> * filter-message-search.c (header_full_regex): impl. svn path=/trunk/; revision=6685
Diffstat (limited to 'filter/filter-message-search.c')
-rw-r--r--filter/filter-message-search.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/filter/filter-message-search.c b/filter/filter-message-search.c
index a4db6c4373..d374422dfd 100644
--- a/filter/filter-message-search.c
+++ b/filter/filter-message-search.c
@@ -41,6 +41,7 @@ static ESExpResult *header_ends_with (struct _ESExp *f, int argc, struct _ESExpR
static ESExpResult *header_exists (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
static ESExpResult *header_soundex (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 *header_full_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);
static ESExpResult *body_regex (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
@@ -69,6 +70,7 @@ static struct {
{ "header-exists", (ESExpFunc *) header_exists, 0 },
{ "header-soundex", (ESExpFunc *) header_soundex, 0 },
{ "header-regex", (ESExpFunc *) header_regex, 0 },
+ { "header-full-regex", (ESExpFunc *) header_full_regex, 0 },
{ "user-tag", (ESExpFunc *) user_tag, 0 },
{ "user-flag", (ESExpFunc *) user_flag, 0 },
{ "get-sent-date", (ESExpFunc *) get_sent_date, 0 },
@@ -372,7 +374,75 @@ header_regex (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMess
regmsg = g_malloc0 (reglen + 1);
regerror (regerr, &regexpat, regmsg, reglen);
camel_exception_setv (fms->ex, CAMEL_EXCEPTION_SYSTEM,
- "Failed to perform regex search on message body: %s",
+ _("Failed to perform regex search on message header: %s"),
+ regmsg);
+ g_free (regmsg);
+ regfree (&regexpat);
+ } else {
+ if (contents) {
+ fltmatch = g_new0 (regmatch_t, regexpat.re_nsub);
+
+ if (!regexec (&regexpat, contents, regexpat.re_nsub, fltmatch, 0))
+ matched = TRUE;
+
+ g_free (fltmatch);
+ regfree (&regexpat);
+ }
+ }
+ }
+
+ r = e_sexp_result_new (ESEXP_RES_BOOL);
+ r->value.bool = matched;
+
+ return r;
+}
+
+static gchar *
+get_full_header (CamelMimeMessage *message)
+{
+ CamelMimePart *mp = CAMEL_MIME_PART (message);
+ GString *str = g_string_new ("");
+ char *ret;
+ struct _header_raw *h;
+
+ for (h = mp->headers; h; h = h->next) {
+ if (h->value != NULL)
+ g_string_sprintfa (str, "%s%s%s\n", h->name,
+ isspace (h->value[0]) ? ":" : ": ", h->value);
+ }
+
+ ret = str->str;
+ g_string_free (str, FALSE);
+
+ return ret;
+}
+
+static ESExpResult *
+header_full_regex (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms)
+{
+ gboolean matched = FALSE;
+ ESExpResult *r;
+
+ if (argc == 1) {
+ char *match = (argv[0])->value.string;
+ regex_t regexpat; /* regex patern */
+ regmatch_t *fltmatch;
+ gint regerr = 0;
+ size_t reglen = 0;
+ gchar *regmsg;
+ char *contents;
+
+ contents = get_full_header (fms->message);
+
+ regerr = regcomp (&regexpat, match, REG_EXTENDED | REG_NEWLINE | REG_ICASE);
+ if (regerr) {
+ /* regerror gets called twice to get the full error string
+ length to do proper posix error reporting */
+ reglen = regerror (regerr, &regexpat, 0, 0);
+ regmsg = g_malloc0 (reglen + 1);
+ regerror (regerr, &regexpat, regmsg, reglen);
+ camel_exception_setv (fms->ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Failed to perform regex search on message header: %s"),
regmsg);
g_free (regmsg);
regfree (&regexpat);
@@ -387,6 +457,7 @@ header_regex (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMess
regfree (&regexpat);
}
}
+ g_free (contents);
}
r = e_sexp_result_new (ESEXP_RES_BOOL);