diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2001-07-13 23:06:14 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2001-07-13 23:06:14 +0800 |
commit | f2757356ba1c41da816b4e524b54846c16652ada (patch) | |
tree | f48951dbce6f1e330ac25b55e8c038737803cff7 /camel | |
parent | 2673cf170b9fcd1e51cddd195b81d5d2ea3928ea (diff) | |
download | gsoc2013-evolution-f2757356ba1c41da816b4e524b54846c16652ada.tar gsoc2013-evolution-f2757356ba1c41da816b4e524b54846c16652ada.tar.gz gsoc2013-evolution-f2757356ba1c41da816b4e524b54846c16652ada.tar.bz2 gsoc2013-evolution-f2757356ba1c41da816b4e524b54846c16652ada.tar.lz gsoc2013-evolution-f2757356ba1c41da816b4e524b54846c16652ada.tar.xz gsoc2013-evolution-f2757356ba1c41da816b4e524b54846c16652ada.tar.zst gsoc2013-evolution-f2757356ba1c41da816b4e524b54846c16652ada.zip |
We now use a structure as the bucket data rather than just a cache level
2001-07-13 Jeffrey Stedfast <fejj@ximian.com>
* camel-uid-cache.c (camel_uid_cache_new): We now use a structure
as the bucket data rather than just a cache level so set the save
state to TRUE.
(maybe_write_uid): We only save the uid if the cache levels are
the same *and* if the save state is TRUE.
(free_uid): Free the state value.
(camel_uid_cache_get_new_uids): New uids that get added to the
cache start with a save state of FALSE.
(camel_uid_cache_save_uid): Set the save state of the uid to
TRUE. What should we do if the uid isn't already in the cache?
Currently I make it add the uid, but maybe it shouldn't?
* providers/imap/camel-imap-folder.c (imap_filter_timeout): Update
to reflect CamelFilterDriver API changes.
* camel-filter-driver.c (camel_filter_driver_filter_folder): Take
a cache argument so we can tell the cache whether or not the uid
should be saved (meaning we have successfully filtered it).
svn path=/trunk/; revision=11084
Diffstat (limited to 'camel')
-rw-r--r-- | camel/ChangeLog | 21 | ||||
-rw-r--r-- | camel/camel-filter-driver.c | 6 | ||||
-rw-r--r-- | camel/camel-filter-driver.h | 13 | ||||
-rw-r--r-- | camel/camel-uid-cache.c | 88 | ||||
-rw-r--r-- | camel/camel-uid-cache.h | 7 | ||||
-rw-r--r-- | camel/providers/imap/camel-imap-folder.c | 3 |
6 files changed, 106 insertions, 32 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 20da6bff90..d5760cc10e 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,24 @@ +2001-07-13 Jeffrey Stedfast <fejj@ximian.com> + + * camel-uid-cache.c (camel_uid_cache_new): We now use a structure + as the bucket data rather than just a cache level so set the save + state to TRUE. + (maybe_write_uid): We only save the uid if the cache levels are + the same *and* if the save state is TRUE. + (free_uid): Free the state value. + (camel_uid_cache_get_new_uids): New uids that get added to the + cache start with a save state of FALSE. + (camel_uid_cache_save_uid): Set the save state of the uid to + TRUE. What should we do if the uid isn't already in the cache? + Currently I make it add the uid, but maybe it shouldn't? + + * providers/imap/camel-imap-folder.c (imap_filter_timeout): Update + to reflect CamelFilterDriver API changes. + + * camel-filter-driver.c (camel_filter_driver_filter_folder): Take + a cache argument so we can tell the cache whether or not the uid + should be saved (meaning we have successfully filtered it). + 2001-07-12 Jeffrey Stedfast <fejj@ximian.com> * camel-filter-driver.c (camel_filter_driver_filter_message): diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c index 6ecc4bffc0..c77c2d90b2 100644 --- a/camel/camel-filter-driver.c +++ b/camel/camel-filter-driver.c @@ -712,6 +712,7 @@ fail: * camel_filter_driver_filter_folder: * @driver: CamelFilterDriver * @folder: CamelFolder to be filtered + * @cache: UID cache (needed for POP folders) * @uids: message uids to be filtered or NULL (as a shortcut to filter all messages) * @remove: TRUE to mark filtered messages as deleted * @ex: exception @@ -724,7 +725,7 @@ fail: * **/ int -camel_filter_driver_filter_folder (CamelFilterDriver *driver, CamelFolder *folder, +camel_filter_driver_filter_folder (CamelFilterDriver *driver, CamelFolder *folder, CamelUIDCache *cache, GPtrArray *uids, gboolean remove, CamelException *ex) { struct _CamelFilterDriverPrivate *p = _PRIVATE (driver); @@ -793,6 +794,9 @@ camel_filter_driver_filter_folder (CamelFilterDriver *driver, CamelFolder *folde CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_SEEN); + if (cache) + camel_uid_cache_save_uid (cache, uids->pdata[i]); + camel_object_unref (CAMEL_OBJECT (message)); } diff --git a/camel/camel-filter-driver.h b/camel/camel-filter-driver.h index 7f4f3f7f15..ff7028a890 100644 --- a/camel/camel-filter-driver.h +++ b/camel/camel-filter-driver.h @@ -27,6 +27,7 @@ #include <camel/camel-object.h> #include <camel/camel-session.h> #include <camel/camel-folder.h> +#include <camel/camel-uid-cache.h> #define CAMEL_FILTER_DRIVER_TYPE (camel_filter_driver_get_type()) #define CAMEL_FILTER_DRIVER(obj) CAMEL_CHECK_CAST (obj, camel_filter_driver_get_type (), CamelFilterDriver) @@ -75,11 +76,13 @@ void camel_filter_driver_add_rule (CamelFilterDriver *d, const char *name, con int camel_filter_driver_filter_message (CamelFilterDriver *driver, CamelMimeMessage *message, CamelMessageInfo *info, const char *uri, - CamelFolder *source, const char *source_url, const char *original_source_url, - CamelException *ex); -int camel_filter_driver_filter_mbox (CamelFilterDriver *driver, const char *mbox, const char *original_source_url, - CamelException *ex); -int camel_filter_driver_filter_folder (CamelFilterDriver *driver, CamelFolder *folder, + CamelFolder *source, const char *source_url, + const char *original_source_url, CamelException *ex); + +int camel_filter_driver_filter_mbox (CamelFilterDriver *driver, const char *mbox, + const char *original_source_url, CamelException *ex); + +int camel_filter_driver_filter_folder (CamelFilterDriver *driver, CamelFolder *folder, CamelUIDCache *cache, GPtrArray *uids, gboolean remove, CamelException *ex); #if 0 diff --git a/camel/camel-uid-cache.c b/camel/camel-uid-cache.c index 83305c1fd3..37cbde3110 100644 --- a/camel/camel-uid-cache.c +++ b/camel/camel-uid-cache.c @@ -35,6 +35,11 @@ #include "camel-uid-cache.h" +struct _uid_state { + int level; + gboolean save; +}; + static void free_uid (gpointer key, gpointer value, gpointer data); static void maybe_write_uid (gpointer key, gpointer value, gpointer data); @@ -55,37 +60,42 @@ camel_uid_cache_new (const char *filename) struct stat st; char *buf, **uids; int fd, i; - + fd = open (filename, O_RDWR | O_CREAT, 0700); if (fd == -1) return NULL; - + if (fstat (fd, &st) != 0) { close (fd); return NULL; } buf = g_malloc (st.st_size + 1); - + if (read (fd, buf, st.st_size) == -1) { close (fd); g_free (buf); return NULL; } buf[st.st_size] = '\0'; - + cache = g_new (CamelUIDCache, 1); cache->fd = fd; cache->level = 1; cache->uids = g_hash_table_new (g_str_hash, g_str_equal); - + uids = g_strsplit (buf, "\n", 0); g_free (buf); for (i = 0; uids[i]; i++) { - g_hash_table_insert (cache->uids, uids[i], - GINT_TO_POINTER (cache->level)); + struct _uid_state *state; + + state = g_new (struct _uid_state, 1); + state->level = cache->level; + state->save = TRUE; + + g_hash_table_insert (cache->uids, uids[i], state); } g_free (uids); - + return cache; } @@ -110,13 +120,15 @@ static void maybe_write_uid (gpointer key, gpointer value, gpointer data) { CamelUIDCache *cache = data; - - if (GPOINTER_TO_INT (value) == cache->level) { + struct _uid_state *state = value; + + if (state && state->level == cache->level && state->save) { write (cache->fd, key, strlen (key)); write (cache->fd, "\n", 1); } } + /** * camel_uid_cache_destroy: * @cache: a CamelUIDCache @@ -136,8 +148,10 @@ static void free_uid (gpointer key, gpointer value, gpointer data) { g_free (key); + g_free (value); } + /** * camel_uid_cache_get_new_uids: * @cache: a CamelUIDCache @@ -153,28 +167,62 @@ GPtrArray * camel_uid_cache_get_new_uids (CamelUIDCache *cache, GPtrArray *uids) { GPtrArray *new_uids; - gpointer old_uid, old_level; + gpointer old_uid; char *uid; int i; - + new_uids = g_ptr_array_new (); cache->level++; - + for (i = 0; i < uids->len; i++) { + struct _uid_state *state; + uid = uids->pdata[i]; - if (g_hash_table_lookup_extended (cache->uids, uid, - &old_uid, &old_level)) { + if (g_hash_table_lookup_extended (cache->uids, uid, &old_uid, &state)) { g_hash_table_remove (cache->uids, uid); g_free (old_uid); - } else + } else { g_ptr_array_add (new_uids, g_strdup (uid)); - g_hash_table_insert (cache->uids, g_strdup (uid), - GINT_TO_POINTER (cache->level)); + state = g_new (struct _uid_state, 1); + state->save = FALSE; + } + + state->level = cache->level; + g_hash_table_insert (cache->uids, g_strdup (uid), state); } - + return new_uids; } + +/** + * camel_uid_cache_save_uid: + * @cache: a CamelUIDCache + * @uid: a uid to save + * + * Marks a uid for saving. + **/ +void +camel_uid_cache_save_uid (CamelUIDCache *cache, const char *uid) +{ + struct _uid_state *state; + gpointer old_uid; + + g_return_if_fail (uid != NULL); + + if (g_hash_table_lookup_extended (cache->uids, uid, &old_uid, &state)) { + state->save = TRUE; + state->level = cache->level; + } else { + state = g_new (struct _uid_state, 1); + state->save = TRUE; + state->level = cache->level; + + g_hash_table_insert (cache->uids, g_strdup (uid), state); + } +} + + /** * camel_uid_cache_free_uids: * @uids: an array returned from camel_uid_cache_get_new_uids() @@ -185,7 +233,7 @@ void camel_uid_cache_free_uids (GPtrArray *uids) { int i; - + for (i = 0; i < uids->len; i++) g_free (uids->pdata[i]); g_ptr_array_free (uids, TRUE); diff --git a/camel/camel-uid-cache.h b/camel/camel-uid-cache.h index 98838b30c6..2a381f0be0 100644 --- a/camel/camel-uid-cache.h +++ b/camel/camel-uid-cache.h @@ -43,14 +43,13 @@ CamelUIDCache *camel_uid_cache_new (const char *filename); gboolean camel_uid_cache_save (CamelUIDCache *cache); void camel_uid_cache_destroy (CamelUIDCache *cache); -GPtrArray *camel_uid_cache_get_new_uids (CamelUIDCache *cache, - GPtrArray *uids); -void camel_uid_cache_free_uids (GPtrArray *uids); +GPtrArray *camel_uid_cache_get_new_uids (CamelUIDCache *cache, GPtrArray *uids); +void camel_uid_cache_save_uid (CamelUIDCache *cache, const char *uid); +void camel_uid_cache_free_uids (GPtrArray *uids); #ifdef __cplusplus } #endif /* __cplusplus */ - #endif /* CAMEL_UID_CACHE_H */ diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c index 80f12e42a6..1d119cf4d0 100644 --- a/camel/providers/imap/camel-imap-folder.c +++ b/camel/providers/imap/camel-imap-folder.c @@ -1677,8 +1677,7 @@ imap_filter_timeout (gpointer user_data) "incoming", &ex); if (driver) { - camel_filter_driver_filter_folder (driver, - ftd->folder, + camel_filter_driver_filter_folder (driver, ftd->folder, NULL, ftd->recents, FALSE, &ex); if (camel_exception_is_set (&ex)) |