aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-07-15 21:45:22 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-07-18 00:08:46 +0800
commit4de572679748a0586b9a9c3bf34c40ea5102e826 (patch)
treefa6815753e6fc1fd8f922b0a42c42a373256598c
parent079fc1a78d35d79350b7390ca3a76f65f9f22841 (diff)
downloadgsoc2013-evolution-4de572679748a0586b9a9c3bf34c40ea5102e826.tar
gsoc2013-evolution-4de572679748a0586b9a9c3bf34c40ea5102e826.tar.gz
gsoc2013-evolution-4de572679748a0586b9a9c3bf34c40ea5102e826.tar.bz2
gsoc2013-evolution-4de572679748a0586b9a9c3bf34c40ea5102e826.tar.lz
gsoc2013-evolution-4de572679748a0586b9a9c3bf34c40ea5102e826.tar.xz
gsoc2013-evolution-4de572679748a0586b9a9c3bf34c40ea5102e826.tar.zst
gsoc2013-evolution-4de572679748a0586b9a9c3bf34c40ea5102e826.zip
Add mail_folder_cache_has_folder_info().
Returns whether MailFolderCache has information about the folder described by the CamelStore and folder name. This does not necessarily mean it has the CamelFolder instance, but it at least has some meta-data about it. You can use this function as a folder existence test.
-rw-r--r--libemail-engine/mail-folder-cache.c38
-rw-r--r--libemail-engine/mail-folder-cache.h4
-rw-r--r--libemail-engine/mail-vfolder.c41
3 files changed, 73 insertions, 10 deletions
diff --git a/libemail-engine/mail-folder-cache.c b/libemail-engine/mail-folder-cache.c
index 7c778cae2a..bf4e8b3fdb 100644
--- a/libemail-engine/mail-folder-cache.c
+++ b/libemail-engine/mail-folder-cache.c
@@ -1628,6 +1628,44 @@ mail_folder_cache_note_folder (MailFolderCache *cache,
}
/**
+ * mail_folder_cache_has_folder_info:
+ * @cache: a #MailFolderCache
+ * @store: a #CamelStore
+ * @folder_name: a folder name
+ *
+ * Returns whether @cache has information about the folder described by
+ * @store and @folder_name. This does not necessarily mean it has the
+ * #CamelFolder instance, but it at least has some meta-data about it.
+ *
+ * You can use this function as a folder existence test.
+ *
+ * Returns: %TRUE if @cache has folder info, %FALSE otherwise
+ **/
+gboolean
+mail_folder_cache_has_folder_info (MailFolderCache *cache,
+ CamelStore *store,
+ const gchar *folder_name)
+{
+ StoreInfo *si;
+ gboolean has_info = FALSE;
+
+ g_return_val_if_fail (MAIL_IS_FOLDER_CACHE (cache), FALSE);
+ g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE);
+ g_return_val_if_fail (folder_name != NULL, FALSE);
+
+ if (cache->priv->stores == NULL)
+ return FALSE;
+
+ g_rec_mutex_lock (&cache->priv->stores_mutex);
+ si = g_hash_table_lookup (cache->priv->stores, store);
+ if (si != NULL)
+ has_info = g_hash_table_contains (si->folders, folder_name);
+ g_rec_mutex_unlock (&cache->priv->stores_mutex);
+
+ return has_info;
+}
+
+/**
* mail_folder_cache_get_folder_from_uri:
*
* Gets the #CamelFolder for the supplied @uri.
diff --git a/libemail-engine/mail-folder-cache.h b/libemail-engine/mail-folder-cache.h
index 4581552524..02c305ecea 100644
--- a/libemail-engine/mail-folder-cache.h
+++ b/libemail-engine/mail-folder-cache.h
@@ -117,6 +117,10 @@ void mail_folder_cache_note_store (MailFolderCache *cache,
gpointer data);
void mail_folder_cache_note_folder (MailFolderCache *cache,
CamelFolder *folder);
+gboolean mail_folder_cache_has_folder_info
+ (MailFolderCache *cache,
+ CamelStore *store,
+ const gchar *folder_name);
gboolean mail_folder_cache_get_folder_from_uri
(MailFolderCache *cache,
const gchar *uri,
diff --git a/libemail-engine/mail-vfolder.c b/libemail-engine/mail-vfolder.c
index fbddfd8110..afd7a03cad 100644
--- a/libemail-engine/mail-vfolder.c
+++ b/libemail-engine/mail-vfolder.c
@@ -57,6 +57,32 @@ static void rule_changed (EFilterRule *rule, CamelFolder *folder);
/* ********************************************************************** */
+static gboolean
+vfolder_cache_has_folder_info (EMailSession *session,
+ const gchar *folder_uri)
+{
+ MailFolderCache *folder_cache;
+ CamelStore *store = NULL;
+ gchar *folder_name = NULL;
+ gboolean cache_has_info = FALSE;
+
+ folder_cache = e_mail_session_get_folder_cache (session);
+
+ e_mail_folder_uri_parse (
+ CAMEL_SESSION (session), folder_uri,
+ &store, &folder_name, NULL);
+
+ if (store != NULL && folder_name != NULL) {
+ cache_has_info = mail_folder_cache_has_folder_info (
+ folder_cache, store, folder_name);
+ }
+
+ g_clear_object (&store);
+ g_free (folder_name);
+
+ return cache_has_info;
+}
+
static GList *
vfolder_get_include_subfolders_uris (EMailSession *session,
const gchar *base_uri,
@@ -292,17 +318,15 @@ vfolder_adduri_exec (struct _adduri_msg *m,
GError **error)
{
CamelFolder *folder = NULL;
- MailFolderCache *folder_cache;
+ gboolean cache_has_info;
if (vfolder_shutdown)
return;
- folder_cache = e_mail_session_get_folder_cache (m->session);
-
- /* we dont try lookup the cache if we are removing it, its no longer there */
+ cache_has_info = vfolder_cache_has_folder_info (
+ m->session, m->uri[0] == '*' ? m->uri + 1 : m->uri);
- if (!m->remove &&
- !mail_folder_cache_get_folder_from_uri (folder_cache, m->uri[0] == '*' ? m->uri + 1 : m->uri, NULL)) {
+ if (!m->remove && !cache_has_info) {
g_warning (
"Folder '%s' disappeared while I was "
"adding/removing it to/from my vfolder", m->uri);
@@ -767,18 +791,15 @@ rule_add_sources (EMailSession *session,
EMVFolderRule *rule)
{
GList *sources_uri = *sources_urip;
- MailFolderCache *folder_cache;
GList *head, *link;
- folder_cache = e_mail_session_get_folder_cache (session);
-
head = g_queue_peek_head_link (queue);
for (link = head; link != NULL; link = g_list_next (link)) {
const gchar *uri = link->data;
/* always pick fresh folders - they are
* from CamelStore's folders bag anyway */
- if (mail_folder_cache_get_folder_from_uri (folder_cache, uri, NULL)) {
+ if (vfolder_cache_has_folder_info (session, uri)) {
/* "tag" uris with subfolders with a star prefix */
if (!rule || !em_vfolder_rule_source_get_include_subfolders (rule, uri))
sources_uri = g_list_prepend (sources_uri, g_strdup (uri));