New file - lists rules appropriate for vfolders (no actions, etc).

2000-05-27  Not Zed  <NotZed@HelixCode.com>

        * vfoldertypes.xml: New file - lists rules appropriate for
        vfolders (no actions, etc).

        * Makefile.am (EXTRA_DIST): Add vfoldertypes.xml

        * filter-driver.c (filter_driver_expand_option): Made public from
        expand_filter_option.
        (filter_driver_rule_count): find out how many user rules are
        defined.
        (filter_driver_rule_get): Get a user rule by index.

svn path=/trunk/; revision=3240
This commit is contained in:
Not Zed
2000-05-28 06:14:53 +00:00
committed by Michael Zucci
parent 350fde8167
commit d11f78c349
5 changed files with 133 additions and 30 deletions

View File

@ -1,3 +1,16 @@
2000-05-27 Not Zed <NotZed@HelixCode.com>
* vfoldertypes.xml: New file - lists rules appropriate for
vfolders (no actions, etc).
* Makefile.am (EXTRA_DIST): Add vfoldertypes.xml
* filter-driver.c (filter_driver_expand_option): Made public from
expand_filter_option.
(filter_driver_rule_count): find out how many user rules are
defined.
(filter_driver_rule_get): Get a user rule by index.
2000-05-21 Ettore Perazzoli <ettore@helixcode.com>
* filter-druid.c: Don't pass an empty URL to `gtk_html_begin()'

View File

@ -28,8 +28,10 @@ libfilter_la_SOURCES = \
filter-driver.c \
filter-driver.h
EXTRA_DIST = blank.xpm check.xpm filtertypes.xml
EXTRA_DIST = blank.xpm check.xpm \
filtertypes.xml vfoldertypes.xml
# basic rules.
filterdir = $(prefix)/share/evolution
filter_DATA = filtertypes.xml
filter_DATA = filtertypes.xml vfoldertypes.xml

View File

@ -301,46 +301,52 @@ expand_variables(GString *out, char *source, GList *args, GHashTable *globals)
/*
build an expression for the filter
*/
static void
expand_filter_option(FilterDriver *d, GString *s, GString *action, struct filter_option *op)
void
filter_driver_expand_option(FilterDriver *d, GString *s, GString *action, struct filter_option *op)
{
GList *optionl;
FilterArg *arg;
struct _FilterDriverPrivate *p = _PRIVATE(d);
g_string_append(s, "(and ");
optionl = op->options;
while (optionl) {
struct filter_optionrule *or = optionl->data;
if (or->rule->type == FILTER_XML_MATCH
|| or->rule->type == FILTER_XML_EXCEPT) {
if (or->args) {
arg = or->args->data;
if (arg) {
printf("arg = %s\n", arg->name);
if (s) {
g_string_append(s, "(and ");
optionl = op->options;
while (optionl) {
struct filter_optionrule *or = optionl->data;
if (or->rule->type == FILTER_XML_MATCH
|| or->rule->type == FILTER_XML_EXCEPT) {
if (or->args) {
arg = or->args->data;
if (arg) {
printf("arg = %s\n", arg->name);
}
}
expand_variables(s, or->rule->code, or->args, p->globals);
}
expand_variables(s, or->rule->code, or->args, p->globals);
optionl = g_list_next(optionl);
}
optionl = g_list_next(optionl);
g_string_append(s, ")");
}
g_string_append(s, ")");
g_string_append(action, "(begin ");
optionl = op->options;
while (optionl) {
struct filter_optionrule *or = optionl->data;
if (or->rule->type == FILTER_XML_ACTION) {
expand_variables(action, or->rule->code, or->args, p->globals);
g_string_append(action, " ");
if (action) {
g_string_append(action, "(begin ");
optionl = op->options;
while (optionl) {
struct filter_optionrule *or = optionl->data;
if (or->rule->type == FILTER_XML_ACTION) {
expand_variables(action, or->rule->code, or->args, p->globals);
g_string_append(action, " ");
}
optionl = g_list_next(optionl);
}
optionl = g_list_next(optionl);
g_string_append(action, ")");
}
g_string_append(action, ")");
printf("combined rule '%s'\n", s->str);
printf("combined action '%s'\n", action->str);
if (s)
printf("combined rule '%s'\n", s->str);
if (action)
printf("combined action '%s'\n", action->str);
}
static ESExpResult *
@ -522,6 +528,20 @@ close_folders(FilterDriver *d)
return 0;
}
int
filter_driver_rule_count(FilterDriver *d)
{
struct _FilterDriverPrivate *p = _PRIVATE(d);
return g_list_length(p->options);
}
struct filter_option *
filter_driver_rule_get(FilterDriver *d, int n)
{
struct _FilterDriverPrivate *p = _PRIVATE(d);
return g_list_nth_data(p->options, n);
}
int
filter_driver_run(FilterDriver *d, CamelFolder *source, CamelFolder *inbox)
{
@ -549,7 +569,7 @@ filter_driver_run(FilterDriver *d, CamelFolder *source, CamelFolder *inbox)
s = g_string_new("");
a = g_string_new("");
expand_filter_option(d, s, a, fo);
filter_driver_expand_option(d, s, a, fo);
printf("searching expression %s\n", s->str);
p->matches = camel_folder_search_by_expression (p->source, s->str, p->ex);

View File

@ -25,6 +25,7 @@
#include <gtk/gtk.h>
#include <camel/camel-session.h>
#include <camel/camel-folder.h>
#include "filter-xml.h"
#define FILTER_DRIVER(obj) GTK_CHECK_CAST (obj, filter_driver_get_type (), FilterDriver)
#define FILTER_DRIVER_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, filter_driver_get_type (), FilterDriverClass)
@ -55,4 +56,11 @@ void filter_driver_set_global(FilterDriver *, const char *name, const char *valu
/* apply rules to a folder, unmatched messages goto inbox, if not NULL */
int filter_driver_run(FilterDriver *d, CamelFolder *source, CamelFolder *inbox);
/* generate the search query/action string for a filter option */
void filter_driver_expand_option(FilterDriver *d, GString *s, GString *action, struct filter_option *op);
/* get info about rules (options) */
int filter_driver_rule_count(FilterDriver *d);
struct filter_option *filter_driver_rule_get(FilterDriver *d, int n);
#endif /* ! _FILTER_DRIVER_H */

60
filter/vfoldertypes.xml Normal file
View File

@ -0,0 +1,60 @@
<?xml version="1.0"?>
<filterdescription>
<ruleset type="match">
<rule name="from-address">
<code>
(match-all (header-contains "From" ${sender}))
</code>
<description lang="en">The From address matches <source type="address" name="sender">sender(s)</source>.</description>
</rule>
<rule name="to-address">
<code>
(match-all (header-contains "To" ${receipient}))
</code>
<description lang="en">The To address matches <source type="address" name="receipient">receipients</source>.</description>
</rule>
<rule name="subject-contains">
<code>
(match-all (header-contains "Subject" ${words}))
</code>
<description lang="en">The Subject contains <source type="folder" name="words">words</source>.</description>
</rule>
<rule name="cc-address">
<code>
(match-all (header-contains "CC" ${self-email}))
</code>
<description lang="en">I am in the cc list.</description>
</rule>
</ruleset>
<ruleset type="except">
<rule name="except-me">
<code>
(match-all (not (header-contains "To" ${self-email})))
</code>
<description language="en">I am the receipient.</description>
</rule>
</ruleset>
<optionset>
<option type="match">
<description language="en">For matching messages.</description>
</option>
<option type="match">
<description language="en">Messages from a certain person.</description>
<optionrule type="match" rule="from-address"/>
</option>
<option type="match">
<description language="en">Messages to a certain address.</description>
<optionrule type="match" rule="to-address"/>
</option>
<option type="match">
<description language="en">Messages with a given subject.</description>
<optionrule type="match" rule="subject-contains"/>
</option>
</optionset>
</filterdescription>