aboutsummaryrefslogtreecommitdiffstats
path: root/filter/filter-driver.c
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-07-03 07:18:06 +0800
committerDan Winship <danw@src.gnome.org>2000-07-03 07:18:06 +0800
commitf1701f224d58f8a0b49da23d85cf425e303cc6ec (patch)
tree7de2bd9ff7b659d94970ec9a35b7d27c16e2250e /filter/filter-driver.c
parente497e9ad28cdc787d66ea40e924b2775890e123c (diff)
downloadgsoc2013-evolution-f1701f224d58f8a0b49da23d85cf425e303cc6ec.tar.gz
gsoc2013-evolution-f1701f224d58f8a0b49da23d85cf425e303cc6ec.tar.zst
gsoc2013-evolution-f1701f224d58f8a0b49da23d85cf425e303cc6ec.zip
kill filter_driver_set_session and filter_driver_set_rules and instead
* filter-driver.c (filter_driver_new): kill filter_driver_set_session and filter_driver_set_rules and instead make filter_driver_new take the rules and a callback function it can use to turn URIs into folders. (open_folder): Use the callback function rather than calling camel directly: some URIs need special handling to turn them into stores and folders correctly, so let the mailer do that. svn path=/trunk/; revision=3859
Diffstat (limited to 'filter/filter-driver.c')
-rw-r--r--filter/filter-driver.c75
1 files changed, 22 insertions, 53 deletions
diff --git a/filter/filter-driver.c b/filter/filter-driver.c
index 8b1430ba21..7b3f361b4a 100644
--- a/filter/filter-driver.c
+++ b/filter/filter-driver.c
@@ -39,6 +39,7 @@
struct _FilterDriverPrivate {
GList *rules, *options;
GHashTable *globals; /* global variables */
+ FilterFolderFetcher fetcher;
/* run-time data */
GHashTable *folders; /* currently open folders */
@@ -172,42 +173,35 @@ filter_driver_finalise (GtkObject *obj)
/**
* filter_driver_new:
+ * @system: path to system rules
+ * @user: path to user rules
+ * @fetcher: function to call to fetch folders
*
* Create a new FilterDriver object.
*
* Return value: A new FilterDriver widget.
**/
FilterDriver *
-filter_driver_new (void)
+filter_driver_new (const char *system, const char *user, FilterFolderFetcher fetcher)
{
- FilterDriver *new = FILTER_DRIVER (gtk_type_new (filter_driver_get_type ()));
- return new;
-}
+ FilterDriver *new;
+ struct _FilterDriverPrivate *p;
+ xmlDocPtr desc, filt;
+ new = FILTER_DRIVER (gtk_type_new (filter_driver_get_type ()));
+ p = _PRIVATE(new);
-void filter_driver_set_session(FilterDriver *d, CamelSession *s)
-{
- if (d->session)
- gtk_object_unref((GtkObject *)s);
- d->session = s;
- if (s)
- gtk_object_ref((GtkObject *)s);
-}
+ p->fetcher = fetcher;
-int filter_driver_set_rules(FilterDriver *d, const char *description, const char *filter)
-{
- struct _FilterDriverPrivate *p = _PRIVATE(d);
- xmlDocPtr desc, filt;
-
- printf("Loading system '%s'\nLoading user '%s'\n", description, filter);
+ printf("Loading system '%s'\nLoading user '%s'\n", system, user);
#warning "fix leaks, free xml docs here"
- desc = xmlParseFile(description);
+ desc = xmlParseFile(system);
p->rules = filter_load_ruleset(desc);
- filt = xmlParseFile(filter);
- if( filt == NULL ) {
- g_warning( "Couldn't load filter file %s!", filter );
+ filt = xmlParseFile(user);
+ if (filt == NULL) {
+ g_warning("Couldn't load filter file %s!", user);
p->options = NULL;
} else
p->options = filter_load_optionset(filt, p->rules);
@@ -215,10 +209,11 @@ int filter_driver_set_rules(FilterDriver *d, const char *description, const char
#warning "Zucchi: is this safe? Doesn't seem to cause problems..."
filter_load_ruleset_free (p->rules);
xmlFreeDoc (desc);
-
- return 0;
+
+ return new;
}
+
void filter_driver_set_global(FilterDriver *d, const char *name, const char *value)
{
struct _FilterDriverPrivate *p = _PRIVATE(d);
@@ -454,8 +449,6 @@ do_stop(struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterDriver *d)
static CamelFolder *
open_folder(FilterDriver *d, const char *folder_url)
{
- char *folder, *store;
- CamelStore *camelstore;
CamelFolder *camelfolder;
struct _FilterDriverPrivate *p = _PRIVATE(d);
@@ -464,35 +457,11 @@ open_folder(FilterDriver *d, const char *folder_url)
if (camelfolder)
return camelfolder;
- store = g_strdup(folder_url);
- folder = strrchr(store, '/');
- if (folder == NULL || folder == store || folder[1]==0)
- goto fail;
-
- *folder++ = 0;
- camelstore = camel_session_get_store (d->session, store, p->ex);
- if (camel_exception_get_id (p->ex)) {
- printf ("Could not open store: %s: %s", store, camel_exception_get_description (p->ex));
- goto fail;
- }
-
- camelfolder = camel_store_get_folder (camelstore, folder, TRUE, p->ex);
- if (camel_exception_get_id (p->ex)) {
- printf ("Could not open folder: %s: %s", folder, camel_exception_get_description (p->ex));
- goto fail;
- }
-
- printf("opening folder: %s\n", folder_url);
-
- g_free(store);
-
- g_hash_table_insert(p->folders, g_strdup(folder_url), camelfolder);
+ camelfolder = p->fetcher(folder_url);
+ if (camelfolder)
+ g_hash_table_insert(p->folders, g_strdup(folder_url), camelfolder);
return camelfolder;
-
-fail:
- g_free(store);
- return NULL;
}
static void