[evolution] Bug #465076 - INBOX confusion with outbox



commit 785515dcbd70d041ce3da2e7ea2283e1e7d87a31
Author: Milan Crha <mcrha redhat com>
Date:   Thu Apr 19 13:46:56 2012 +0200

    Bug #465076 - INBOX confusion with outbox

 libemail-engine/e-mail-utils.c          |   26 ++++++++-
 libemail-engine/mail-folder-cache.c     |   90 +++++++++++++++---------------
 plugins/itip-formatter/itip-formatter.c |    6 +-
 3 files changed, 72 insertions(+), 50 deletions(-)
---
diff --git a/libemail-engine/e-mail-utils.c b/libemail-engine/e-mail-utils.c
index e60e08a..fcf24a8 100644
--- a/libemail-engine/e-mail-utils.c
+++ b/libemail-engine/e-mail-utils.c
@@ -128,6 +128,9 @@ em_utils_folder_is_drafts (CamelFolder *folder)
 	CamelFolder *local_drafts_folder;
 	CamelSession *session;
 	CamelStore *store;
+	MailFolderCache *cache;
+	EMailSession *mail_session;
+	CamelFolderInfoFlags flags = 0;
 	EAccountList *account_list;
 	EIterator *iterator;
 	gchar *folder_uri;
@@ -137,14 +140,22 @@ em_utils_folder_is_drafts (CamelFolder *folder)
 
 	store = camel_folder_get_parent_store (folder);
 	session = camel_service_get_session (CAMEL_SERVICE (store));
+	mail_session = E_MAIL_SESSION (session);
 
 	local_drafts_folder =
 		e_mail_session_get_local_folder (
-		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_DRAFTS);
+		mail_session, E_MAIL_LOCAL_FOLDER_DRAFTS);
 
 	if (folder == local_drafts_folder)
 		return TRUE;
 
+	cache = e_mail_session_get_folder_cache (mail_session);
+
+	/* user can select Inbox as his Draft folder - in that case prefer Inbox type */
+	if (mail_folder_cache_get_folder_info_flags (cache, folder, &flags) &&
+	    (flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX)
+		return FALSE;
+
 	folder_uri = e_mail_folder_uri_from_folder (folder);
 
 	account_list = e_get_account_list ();
@@ -184,6 +195,9 @@ em_utils_folder_is_sent (CamelFolder *folder)
 	CamelFolder *local_sent_folder;
 	CamelSession *session;
 	CamelStore *store;
+	MailFolderCache *cache;
+	EMailSession *mail_session;
+	CamelFolderInfoFlags flags = 0;
 	EAccountList *account_list;
 	EIterator *iterator;
 	gchar *folder_uri;
@@ -193,14 +207,22 @@ em_utils_folder_is_sent (CamelFolder *folder)
 
 	store = camel_folder_get_parent_store (folder);
 	session = camel_service_get_session (CAMEL_SERVICE (store));
+	mail_session = E_MAIL_SESSION (session);
 
 	local_sent_folder =
 		e_mail_session_get_local_folder (
-		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_SENT);
+		mail_session, E_MAIL_LOCAL_FOLDER_SENT);
 
 	if (folder == local_sent_folder)
 		return TRUE;
 
+	cache = e_mail_session_get_folder_cache (mail_session);
+
+	/* user can select Inbox as his Sent folder - in that case prefer Inbox type */
+	if (mail_folder_cache_get_folder_info_flags (cache, folder, &flags) &&
+	    (flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX)
+		return FALSE;
+
 	folder_uri = e_mail_folder_uri_from_folder (folder);
 
 	account_list = e_get_account_list ();
diff --git a/libemail-engine/mail-folder-cache.c b/libemail-engine/mail-folder-cache.c
index 5c459ef..32a4b99 100644
--- a/libemail-engine/mail-folder-cache.c
+++ b/libemail-engine/mail-folder-cache.c
@@ -70,7 +70,7 @@ struct _MailFolderCachePrivate {
 	/* Store to storeinfo table, active stores */
 	GHashTable *stores;
 	/* mutex to protect access to the stores hash */
-	GMutex *stores_mutex;
+	GStaticRecMutex stores_mutex;
 	/* List of folder changes to be executed in gui thread */
 	GQueue updates;
 	/* idle source id for flushing all pending updates */
@@ -231,9 +231,9 @@ flush_updates_idle_cb (MailFolderCache *cache)
 {
 	struct _folder_update *up;
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 	while ((up = g_queue_pop_head (&cache->priv->updates)) != NULL) {
-		g_mutex_unlock (cache->priv->stores_mutex);
+		g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 
 		if (up->remove) {
 			if (up->delete) {
@@ -289,10 +289,10 @@ flush_updates_idle_cb (MailFolderCache *cache)
 
 		free_update (up);
 
-		g_mutex_lock (cache->priv->stores_mutex);
+		g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 	}
 	cache->priv->update_id = 0;
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 
 	return FALSE;
 }
@@ -487,14 +487,14 @@ folder_changed_cb (CamelFolder *folder,
 			last_newmail_per_folder, folder,
 			GINT_TO_POINTER (new_latest_received));
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 	if (cache->priv->stores != NULL
 	    && (si = g_hash_table_lookup (cache->priv->stores, parent_store)) != NULL
 	    && (mfi = g_hash_table_lookup (si->folders, full_name)) != NULL
 	    && mfi->folder == folder) {
 		update_1folder (cache, mfi, new, uid, sender, subject, NULL);
 	}
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 
 	g_free (uid);
 	g_free (sender);
@@ -590,11 +590,11 @@ store_folder_subscribed_cb (CamelStore *store,
 {
 	StoreInfo *si;
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 	si = g_hash_table_lookup (cache->priv->stores, store);
 	if (si)
 		setup_folder (cache, info, si);
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 }
 
 static void
@@ -624,7 +624,7 @@ store_folder_unsubscribed_cb (CamelStore *store,
 	StoreInfo *si;
 	struct _folder_info *mfi;
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 	si = g_hash_table_lookup (cache->priv->stores, store);
 	if (si) {
 		mfi = g_hash_table_lookup (si->folders, info->full_name);
@@ -633,7 +633,7 @@ store_folder_unsubscribed_cb (CamelStore *store,
 			g_hash_table_remove (si->folders, mfi->full_name);
 		}
 	}
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 }
 
 static void
@@ -757,7 +757,7 @@ store_folder_renamed_cb (CamelStore *store,
 {
 	StoreInfo *si;
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 	si = g_hash_table_lookup (cache->priv->stores, store);
 	if (si) {
 		GPtrArray *folders = g_ptr_array_new ();
@@ -777,7 +777,7 @@ store_folder_renamed_cb (CamelStore *store,
 		g_ptr_array_free (folders, TRUE);
 
 	}
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 }
 
 static void
@@ -833,7 +833,7 @@ update_folders (CamelStore *store,
 		g_error_free (error);
 	}
 
-	g_mutex_lock (ud->cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&ud->cache->priv->stores_mutex);
 	si = g_hash_table_lookup (ud->cache->priv->stores, store);
 	if (si && !g_cancellable_is_cancelled (ud->cancellable)) {
 		/* The 'si' is still there, so we can remove ourselves from
@@ -844,7 +844,7 @@ update_folders (CamelStore *store,
 		if (fi != NULL)
 			create_folders (ud->cache, fi, si);
 	}
-	g_mutex_unlock (ud->cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&ud->cache->priv->stores_mutex);
 
 	/* Do some extra work for the first update. */
 	if (si != NULL && si->first_update) {
@@ -947,11 +947,11 @@ ping_store (CamelStore *store)
 static gboolean
 ping_cb (MailFolderCache *cache)
 {
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 
 	g_hash_table_foreach (cache->priv->stores, (GHFunc) ping_store, NULL);
 
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 
 	return TRUE;
 }
@@ -982,7 +982,7 @@ store_go_online_cb (CamelStore *store,
 {
 	/* FIXME Not checking result for error. */
 
-	g_mutex_lock (ud->cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&ud->cache->priv->stores_mutex);
 
 	if (g_hash_table_lookup (ud->cache->priv->stores, store) != NULL &&
 		!g_cancellable_is_cancelled (ud->cancellable)) {
@@ -1003,7 +1003,7 @@ store_go_online_cb (CamelStore *store,
 		g_free (ud);
 	}
 
-	g_mutex_unlock (ud->cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&ud->cache->priv->stores_mutex);
 }
 
 static GList *
@@ -1122,7 +1122,7 @@ mail_folder_cache_finalize (GObject *object)
 	priv = MAIL_FOLDER_CACHE_GET_PRIVATE (object);
 
 	g_hash_table_destroy (priv->stores);
-	g_mutex_free (priv->stores_mutex);
+	g_static_rec_mutex_free (&priv->stores_mutex);
 
 	if (priv->ping_id > 0) {
 		g_source_remove (priv->ping_id);
@@ -1174,7 +1174,7 @@ mail_folder_cache_folder_available (MailFolderCache *cache,
 	provider = camel_service_get_provider (service);
 
 	/* Reuse the stores mutex just because it's handy. */
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 
 	folder_uri = e_mail_folder_uri_build (store, folder_name);
 
@@ -1188,7 +1188,7 @@ mail_folder_cache_folder_available (MailFolderCache *cache,
 	else
 		g_free (folder_uri);
 
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 }
 
 static void
@@ -1222,7 +1222,7 @@ mail_folder_cache_folder_unavailable (MailFolderCache *cache,
 	provider = camel_service_get_provider (service);
 
 	/* Reuse the stores mutex just because it's handy. */
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 
 	folder_uri = e_mail_folder_uri_build (store, folder_name);
 
@@ -1239,7 +1239,7 @@ mail_folder_cache_folder_unavailable (MailFolderCache *cache,
 
 	g_free (folder_uri);
 
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 }
 
 static void
@@ -1271,7 +1271,7 @@ mail_folder_cache_folder_deleted (MailFolderCache *cache,
 	session = camel_service_get_session (service);
 
 	/* Reuse the stores mutex just because it's handy. */
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 
 	folder_uri = e_mail_folder_uri_build (store, folder_name);
 
@@ -1291,7 +1291,7 @@ mail_folder_cache_folder_deleted (MailFolderCache *cache,
 
 	g_free (folder_uri);
 
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 }
 
 static void
@@ -1452,7 +1452,7 @@ mail_folder_cache_init (MailFolderCache *cache)
 
 	/* initialize values */
 	cache->priv->stores = g_hash_table_new (NULL, NULL);
-	cache->priv->stores_mutex = g_mutex_new ();
+	g_static_rec_mutex_init (&cache->priv->stores_mutex);
 
 	g_queue_init (&cache->priv->updates);
 	cache->priv->count_sent = getenv("EVOLUTION_COUNT_SENT") != NULL;
@@ -1509,7 +1509,7 @@ mail_folder_cache_note_store (MailFolderCache *cache,
 
 	session = camel_service_get_session (CAMEL_SERVICE (store));
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 
 	si = g_hash_table_lookup (cache->priv->stores, store);
 	if (si == NULL) {
@@ -1563,7 +1563,7 @@ mail_folder_cache_note_store (MailFolderCache *cache,
 
 	g_queue_push_tail (&si->folderinfo_updates, ud);
 
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 
 	/* there is potential for race here, but it is safe as we check
 	 * for the store anyway */
@@ -1614,18 +1614,18 @@ mail_folder_cache_note_folder (MailFolderCache *cache,
 	full_name = camel_folder_get_full_name (folder);
 	parent_store = camel_folder_get_parent_store (folder);
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 	if (cache->priv->stores == NULL
 	    || (si = g_hash_table_lookup (cache->priv->stores, parent_store)) == NULL
 	    || (mfi = g_hash_table_lookup (si->folders, full_name)) == NULL) {
 		w(g_warning("Noting folder before store initialised"));
-		g_mutex_unlock (cache->priv->stores_mutex);
+		g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 		return;
 	}
 
 	/* dont do anything if we already have this */
 	if (mfi->folder == folder) {
-		g_mutex_unlock (cache->priv->stores_mutex);
+		g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 		return;
 	}
 
@@ -1635,7 +1635,7 @@ mail_folder_cache_note_folder (MailFolderCache *cache,
 
 	update_1folder (cache, mfi, 0, NULL, NULL, NULL, NULL);
 
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 
 	g_signal_connect (
 		folder, "changed",
@@ -1660,7 +1660,7 @@ mail_folder_cache_get_folder_from_uri (MailFolderCache *cache,
 	if (cache->priv->stores == NULL)
 		return FALSE;
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 	g_hash_table_foreach (
 		cache->priv->stores, (GHFunc)
 		storeinfo_find_folder_info, &fi);
@@ -1670,7 +1670,7 @@ mail_folder_cache_get_folder_from_uri (MailFolderCache *cache,
 		else
 			*folderp = NULL;
 	}
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 
 	return fi.fi != NULL;
 }
@@ -1689,7 +1689,7 @@ mail_folder_cache_get_folder_info_flags (MailFolderCache *cache,
 	folder_uri = e_mail_folder_uri_from_folder (folder);
 	fi.folder_uri = folder_uri;
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 	g_hash_table_foreach (
 		cache->priv->stores, (GHFunc)
 		storeinfo_find_folder_info, &fi);
@@ -1699,7 +1699,7 @@ mail_folder_cache_get_folder_info_flags (MailFolderCache *cache,
 		else
 			*flags = 0;
 	}
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 
 	g_free (folder_uri);
 
@@ -1725,13 +1725,13 @@ mail_folder_cache_get_folder_has_children (MailFolderCache *cache,
 	folder_uri = e_mail_folder_uri_from_folder (folder);
 	fi.folder_uri = folder_uri;
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 	g_hash_table_foreach (
 		cache->priv->stores, (GHFunc)
 		storeinfo_find_folder_info, &fi);
 	if (found != NULL)
 		*found = fi.fi != NULL;
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 
 	g_free (folder_uri);
 
@@ -1748,14 +1748,14 @@ mail_folder_cache_get_local_folder_uris (MailFolderCache *self,
 	g_return_if_fail (out_queue != NULL);
 
 	/* Reuse the stores mutex just because it's handy. */
-	g_mutex_lock (self->priv->stores_mutex);
+	g_static_rec_mutex_lock (&self->priv->stores_mutex);
 
 	head = g_queue_peek_head_link (&self->priv->local_folder_uris);
 
 	for (link = head; link != NULL; link = g_list_next (link))
 		g_queue_push_tail (out_queue, g_strdup (link->data));
 
-	g_mutex_unlock (self->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&self->priv->stores_mutex);
 }
 
 void
@@ -1768,14 +1768,14 @@ mail_folder_cache_get_remote_folder_uris (MailFolderCache *self,
 	g_return_if_fail (out_queue != NULL);
 
 	/* Reuse the stores mutex just because it's handy. */
-	g_mutex_lock (self->priv->stores_mutex);
+	g_static_rec_mutex_lock (&self->priv->stores_mutex);
 
 	head = g_queue_peek_head_link (&self->priv->remote_folder_uris);
 
 	for (link = head; link != NULL; link = g_list_next (link))
 		g_queue_push_tail (out_queue, g_strdup (link->data));
 
-	g_mutex_unlock (self->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&self->priv->stores_mutex);
 }
 
 void
@@ -1801,7 +1801,7 @@ mail_folder_cache_service_removed (MailFolderCache *cache,
 	if (cache->priv->stores == NULL)
 		return;
 
-	g_mutex_lock (cache->priv->stores_mutex);
+	g_static_rec_mutex_lock (&cache->priv->stores_mutex);
 
 	si = g_hash_table_lookup (cache->priv->stores, service);
 	if (si != NULL) {
@@ -1818,7 +1818,7 @@ mail_folder_cache_service_removed (MailFolderCache *cache,
 		store_info_free (si);
 	}
 
-	g_mutex_unlock (cache->priv->stores_mutex);
+	g_static_rec_mutex_unlock (&cache->priv->stores_mutex);
 }
 
 void
diff --git a/plugins/itip-formatter/itip-formatter.c b/plugins/itip-formatter/itip-formatter.c
index cf17295..b8fd802 100644
--- a/plugins/itip-formatter/itip-formatter.c
+++ b/plugins/itip-formatter/itip-formatter.c
@@ -2739,10 +2739,10 @@ in_proper_folder (CamelFolder *folder)
 
 	if (mail_folder_cache_get_folder_info_flags (folder_cache, folder, &flags)) {
 		/* it should be neither trash nor junk folder, */
-		res = ((flags & CAMEL_FOLDER_TYPE_TRASH) !=  CAMEL_FOLDER_TYPE_TRASH &&
-		       (flags & CAMEL_FOLDER_TYPE_JUNK) != CAMEL_FOLDER_TYPE_JUNK &&
+		res = ((flags & CAMEL_FOLDER_TYPE_MASK) !=  CAMEL_FOLDER_TYPE_TRASH &&
+		       (flags & CAMEL_FOLDER_TYPE_MASK) != CAMEL_FOLDER_TYPE_JUNK &&
 			  /* it can be Inbox */
-			( (flags & CAMEL_FOLDER_TYPE_INBOX) == CAMEL_FOLDER_TYPE_INBOX ||
+			( (flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX ||
 			  /* or any other virtual folder */
 			  CAMEL_IS_VEE_FOLDER (folder) ||
 			  /* or anything else except of sent, outbox or drafts folder */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]