diff options
author | Dan Winship <danw@src.gnome.org> | 2000-07-03 07:18:06 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2000-07-03 07:18:06 +0800 |
commit | f1701f224d58f8a0b49da23d85cf425e303cc6ec (patch) | |
tree | 7de2bd9ff7b659d94970ec9a35b7d27c16e2250e /filter | |
parent | e497e9ad28cdc787d66ea40e924b2775890e123c (diff) | |
download | gsoc2013-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')
-rw-r--r-- | filter/ChangeLog | 10 | ||||
-rw-r--r-- | filter/filter-driver.c | 75 | ||||
-rw-r--r-- | filter/filter-driver.h | 8 |
3 files changed, 35 insertions, 58 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog index 9480f152c5..27436d31b1 100644 --- a/filter/ChangeLog +++ b/filter/ChangeLog @@ -1,3 +1,13 @@ +2000-07-02 Dan Winship <danw@helixcode.com> + + * 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. + 2000-07-01 Ettore Perazzoli <ettore@helixcode.com> * filter-arg-types.c (arg_folder_edit_value): Only allow type 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 diff --git a/filter/filter-driver.h b/filter/filter-driver.h index ad9afca53f..a7a752aecd 100644 --- a/filter/filter-driver.h +++ b/filter/filter-driver.h @@ -38,19 +38,17 @@ struct _FilterDriver { GtkObject parent; struct _FilterDriverPrivate *priv; - - CamelSession *session; }; struct _FilterDriverClass { GtkObjectClass parent_class; }; +typedef CamelFolder *(*FilterFolderFetcher) (const char *uri); + guint filter_driver_get_type (void); -FilterDriver *filter_driver_new (void); +FilterDriver *filter_driver_new (const char *system, const char *user, FilterFolderFetcher fetcher); -void filter_driver_set_session(FilterDriver *, CamelSession *); -int filter_driver_set_rules(FilterDriver *, const char *system, const char *filter); void filter_driver_set_global(FilterDriver *, const char *name, const char *value); /* apply rules to a folder, unmatched messages goto inbox, if not NULL */ |