[evolution/eds-mailer: 1/49] Save pre-built incoming filter s-expressions to disk



commit c8d3db168ce15b19dd99088a1ccf2ab811d7cccb
Author: Jonathon Jongsma <jonathon quotidian org>
Date:   Mon Dec 21 09:11:28 2009 -0600

    Save pre-built incoming filter s-expressions to disk
    
    For the eds-mail split, we don't want to parse the whole filteroptions tree to
    reconstruct the s-expressions for the filters. So we store a cached copy of the
    s-expression in the filters.xml file so that the backend can simply read the
    expression and plug it into the CamelFilterDriver.

 mail/em-filter-context.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/mail/em-filter-context.c b/mail/em-filter-context.c
index 7c17e69..2e084f6 100644
--- a/mail/em-filter-context.c
+++ b/mail/em-filter-context.c
@@ -26,6 +26,7 @@
 #endif
 
 #include <string.h>
+#include <libedataserver/e-xml-utils.h>
 
 #include "em-filter-context.h"
 #include "em-filter-rule.h"
@@ -45,6 +46,7 @@ static void em_filter_context_finalise(GObject *obj);
 static GList *filter_rename_uri(ERuleContext *rc, const gchar *olduri, const gchar *newuri, GCompareFunc cmp);
 static GList *filter_delete_uri(ERuleContext *rc, const gchar *uri, GCompareFunc cmp);
 static EFilterElement *filter_new_element(ERuleContext *rc, const gchar *name);
+static gint filter_context_save (ERuleContext *rc, const gchar *user);
 
 static ERuleContextClass *parent_class = NULL;
 
@@ -86,6 +88,7 @@ em_filter_context_class_init(EMFilterContextClass *klass)
 	rc_class->rename_uri = filter_rename_uri;
 	rc_class->delete_uri = filter_delete_uri;
 	rc_class->new_element = filter_new_element;
+	rc_class->save = filter_context_save;
 }
 
 static void
@@ -296,3 +299,66 @@ filter_new_element(ERuleContext *rc, const gchar *type)
 		return parent_class->new_element(rc, type);
 	}
 }
+
+static gint
+filter_context_save (ERuleContext *context,
+                   const gchar *user)
+{
+	xmlDocPtr doc;
+	xmlNodePtr root, rules, work, cache;
+	GList *l;
+	EFilterRule *rule;
+	struct _rule_set_map *map;
+	gint ret;
+
+	doc = xmlNewDoc ((xmlChar *)"1.0");
+	/* FIXME: set character encoding to UTF-8? */
+	root = xmlNewDocNode (doc, NULL, (xmlChar *)"filteroptions", NULL);
+	xmlDocSetRootElement (doc, root);
+	cache = xmlNewNode (NULL, (xmlChar*) "cache");
+	l = context->rule_set_list;
+	while (l) {
+		map = l->data;
+		rules = xmlNewDocNode (doc, NULL, (xmlChar *)map->name, NULL);
+		xmlAddChild (root, rules);
+		rule = NULL;
+		while ((rule = map->next (context, rule, NULL))) {
+			if (!rule->system) {
+				GString *out = NULL;
+				xmlNodePtr node = NULL;
+
+				work = e_filter_rule_xml_encode (rule);
+				xmlAddChild (rules, work);
+
+				/* cache pre-built s-expressions for filters so
+				 * that backend can read them directly at
+				 * startup */
+				out = g_string_new ("");
+				node = xmlNewNode (NULL, (xmlChar*) "filter");
+				xmlSetProp (node, (xmlChar *)"name", (xmlChar *)rule->name);
+				xmlSetProp (node, (xmlChar *)"source", (xmlChar *)rule->source);
+
+				work = xmlNewNode (NULL, (xmlChar*) "match");
+				e_filter_rule_build_code (rule, out);
+				xmlNodeSetContent (work, (xmlChar*) out->str);
+				g_string_truncate (out, 0);
+				xmlAddChild (node, work);
+
+				work = xmlNewNode (NULL, (xmlChar*) "action");
+				em_filter_rule_build_action ((EMFilterRule*)rule, out);
+				xmlNodeSetContent (work, (xmlChar*) out->str);
+				g_string_free (out, TRUE);
+				xmlAddChild (node, work);
+				xmlAddChild (cache, node);
+			}
+		}
+		l = g_list_next (l);
+	}
+	xmlAddChild (root, cache);
+
+	ret = e_xml_save_file (user, doc);
+
+	xmlFreeDoc (doc);
+
+	return ret;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]