[evolution-data-server] Bug #534369 - New mail notifications for local Inbox don't work



commit 1124cc40ee8af27399123c4caec7f5834cb9f4d6
Author: Milan Crha <mcrha redhat com>
Date:   Thu Oct 14 13:03:53 2010 +0200

    Bug #534369 - New mail notifications for local Inbox don't work

 camel/providers/local/camel-local-folder.c  |   15 ++------
 camel/providers/local/camel-local-store.c   |   49 +++++++++++++++++++++++++++
 camel/providers/local/camel-local-store.h   |    4 ++
 camel/providers/local/camel-maildir-store.c |    7 +++-
 camel/providers/local/camel-mbox-store.c    |   14 +++++---
 camel/providers/local/camel-mh-store.c      |    7 +++-
 camel/providers/local/camel-spool-store.c   |    4 +-
 7 files changed, 79 insertions(+), 21 deletions(-)
---
diff --git a/camel/providers/local/camel-local-folder.c b/camel/providers/local/camel-local-folder.c
index 4d921a6..1a53166 100644
--- a/camel/providers/local/camel-local-folder.c
+++ b/camel/providers/local/camel-local-folder.c
@@ -499,7 +499,6 @@ camel_local_folder_construct (CamelLocalFolder *lf,
                               GError **error)
 {
 	CamelFolder *folder;
-	CamelFolderInfo *fi;
 	const gchar *root_dir_path;
 	gchar *tmp, *statepath;
 #ifndef G_OS_WIN32
@@ -507,7 +506,6 @@ camel_local_folder_construct (CamelLocalFolder *lf,
 	struct stat st;
 #endif
 	gint forceindex, len;
-	CamelURL *url;
 	CamelLocalStore *ls;
 	CamelStore *parent_store;
 	const gchar *full_name;
@@ -609,17 +607,10 @@ camel_local_folder_construct (CamelLocalFolder *lf,
 
 	/* TODO: This probably shouldn't be here? */
 	if ((flags & CAMEL_STORE_FOLDER_CREATE) != 0) {
-		url = camel_url_copy (((CamelService *) parent_store)->url);
-		camel_url_set_fragment (url, full_name);
-
-		fi = camel_folder_info_new ();
-		fi->full_name = g_strdup (full_name);
-		fi->name = g_strdup (name);
-		fi->uri = camel_url_to_string (url, 0);
-		fi->unread = camel_folder_get_unread_message_count (folder);
-		fi->flags = CAMEL_FOLDER_NOCHILDREN;
+		CamelFolderInfo *fi;
 
-		camel_url_free (url);
+		fi = camel_store_get_folder_info_sync (parent_store, full_name, 0, NULL, NULL);
+		g_return_val_if_fail (fi != NULL, lf);
 
 		camel_store_folder_created (parent_store, fi);
 		camel_folder_info_free (fi);
diff --git a/camel/providers/local/camel-local-store.c b/camel/providers/local/camel-local-store.c
index 2984b04..3737bfc 100644
--- a/camel/providers/local/camel-local-store.c
+++ b/camel/providers/local/camel-local-store.c
@@ -32,6 +32,8 @@
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
+#include <libedataserver/e-data-server-util.h>
+
 #include "camel-local-folder.h"
 #include "camel-local-store.h"
 
@@ -110,6 +112,7 @@ construct (CamelService *service,
 	CamelLocalStore *local_store = CAMEL_LOCAL_STORE (service);
 	CamelServiceClass *service_class;
 	gint len;
+	gchar *local_store_path, *local_store_uri;
 
 	/* Chain up to parent's construct() method. */
 	service_class = CAMEL_SERVICE_CLASS (camel_local_store_parent_class);
@@ -122,6 +125,24 @@ construct (CamelService *service,
 	else
 		local_store->toplevel_dir = g_strdup (service->url->path);
 
+	local_store->is_main_store = FALSE;
+
+	local_store_path = g_build_filename (e_get_user_data_dir (), "mail", "local", NULL);
+	local_store_uri = g_filename_to_uri (local_store_path, NULL, NULL);
+	if (local_store_uri) {
+		CamelProvider *provider = service->provider;
+		CamelURL *local_store_url = camel_url_new (local_store_uri, NULL);
+
+		camel_url_set_protocol (local_store_url, service->url->protocol);
+		camel_url_set_host (local_store_url, service->url->host);
+
+		local_store->is_main_store = (provider && provider->url_equal) ? provider->url_equal (service->url, local_store_url) : camel_url_equal (service->url, local_store_url);
+		camel_url_free (local_store_url);
+	}
+
+	g_free (local_store_uri);
+	g_free (local_store_path);
+
 	return TRUE;
 }
 
@@ -543,3 +564,31 @@ local_can_refresh_folder (CamelStore *store, CamelFolderInfo *info, GError **err
 	/* any local folder can be refreshed */
 	return TRUE;
 }
+
+/* Returns whether is this store used as 'On This Computer' main store */
+gboolean
+camel_local_store_is_main_store (CamelLocalStore *store)
+{
+	g_return_val_if_fail (store != NULL, FALSE);
+
+	return store->is_main_store;
+}
+
+guint32
+camel_local_store_get_folder_type_by_full_name (CamelLocalStore *store, const gchar *full_name)
+{
+	g_return_val_if_fail (store != NULL, 0);
+	g_return_val_if_fail (full_name != NULL, 0);
+
+	if (!camel_local_store_is_main_store (store))
+		return CAMEL_FOLDER_TYPE_NORMAL;
+
+	if (g_ascii_strcasecmp (full_name, "Inbox") == 0)
+		return CAMEL_FOLDER_TYPE_INBOX;
+	else if (g_ascii_strcasecmp (full_name, "Outbox") == 0)
+		return CAMEL_FOLDER_TYPE_OUTBOX;
+	else if (g_ascii_strcasecmp (full_name, "Sent") == 0)
+		return CAMEL_FOLDER_TYPE_SENT;
+
+	return CAMEL_FOLDER_TYPE_NORMAL;
+}
diff --git a/camel/providers/local/camel-local-store.h b/camel/providers/local/camel-local-store.h
index 93f66c0..7198fb9 100644
--- a/camel/providers/local/camel-local-store.h
+++ b/camel/providers/local/camel-local-store.h
@@ -53,6 +53,7 @@ struct _CamelLocalStore {
 	CamelStore parent;
 
 	gchar *toplevel_dir;
+	gboolean is_main_store;
 };
 
 struct _CamelLocalStoreClass {
@@ -66,6 +67,9 @@ GType camel_local_store_get_type (void);
 
 const gchar *camel_local_store_get_toplevel_dir (CamelLocalStore *store);
 
+gboolean camel_local_store_is_main_store (CamelLocalStore *store);
+guint32 camel_local_store_get_folder_type_by_full_name (CamelLocalStore *store, const gchar *full_name);
+
 #define camel_local_store_get_full_path(ls, name) \
 	(CAMEL_LOCAL_STORE_GET_CLASS (ls)->get_full_path \
 	(CAMEL_LOCAL_STORE (ls), (name)))
diff --git a/camel/providers/local/camel-maildir-store.c b/camel/providers/local/camel-maildir-store.c
index ae4291d..0acde10 100644
--- a/camel/providers/local/camel-maildir-store.c
+++ b/camel/providers/local/camel-maildir-store.c
@@ -63,7 +63,7 @@ fill_fi (CamelStore *store,
 {
 	CamelFolder *folder;
 
-	folder = camel_object_bag_get (store->folders, fi->full_name);
+	folder = camel_object_bag_peek (store->folders, fi->full_name);
 
 	if (folder == NULL
 	    && (flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0)
@@ -94,6 +94,11 @@ fill_fi (CamelStore *store,
 		g_free (folderpath);
 		g_free (path);
 	}
+
+	if (camel_local_store_is_main_store (CAMEL_LOCAL_STORE (store)) && fi->full_name
+	    && (fi->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_NORMAL)
+		fi->flags = (fi->flags & ~CAMEL_FOLDER_TYPE_MASK)
+			    | camel_local_store_get_folder_type_by_full_name (CAMEL_LOCAL_STORE (store), fi->full_name);
 }
 
 struct _scan_node {
diff --git a/camel/providers/local/camel-mbox-store.c b/camel/providers/local/camel-mbox-store.c
index e56f075..988af8a 100644
--- a/camel/providers/local/camel-mbox-store.c
+++ b/camel/providers/local/camel-mbox-store.c
@@ -104,7 +104,7 @@ fill_fi (CamelStore *store,
 
 	fi->unread = -1;
 	fi->total = -1;
-	folder = camel_object_bag_get (store->folders, fi->full_name);
+	folder = camel_object_bag_peek (store->folders, fi->full_name);
 	if (folder) {
 		if ((flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0)
 			camel_folder_refresh_info_sync (folder, NULL, NULL);
@@ -130,6 +130,11 @@ fill_fi (CamelStore *store,
 		g_free (folderpath);
 		g_free (path);
 	}
+
+	if (camel_local_store_is_main_store (CAMEL_LOCAL_STORE (store)) && fi->full_name
+	    && (fi->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_NORMAL)
+		fi->flags = (fi->flags & ~CAMEL_FOLDER_TYPE_MASK)
+			    | camel_local_store_get_folder_type_by_full_name (CAMEL_LOCAL_STORE (store), fi->full_name);
 }
 
 static CamelFolderInfo *
@@ -481,14 +486,13 @@ mbox_store_get_folder_info_sync (CamelStore *store,
 	fi->unread = -1;
 	fi->total = -1;
 
+	fill_fi (store, fi, flags);
+
 	subdir = g_strdup_printf("%s.sbd", path);
 	if (g_stat (subdir, &st) == 0) {
 		if  (S_ISDIR (st.st_mode))
 			fi->child = scan_dir (store, url, visited, fi, subdir, top, flags, error);
-		else
-			fill_fi (store, fi, flags);
-	} else
-		fill_fi (store, fi, flags);
+	}
 
 	camel_url_free (url);
 
diff --git a/camel/providers/local/camel-mh-store.c b/camel/providers/local/camel-mh-store.c
index 9291f90..7fb31f8 100644
--- a/camel/providers/local/camel-mh-store.c
+++ b/camel/providers/local/camel-mh-store.c
@@ -149,7 +149,7 @@ fill_fi (CamelStore *store,
 {
 	CamelFolder *folder;
 
-	folder = camel_object_bag_get (store->folders, fi->full_name);
+	folder = camel_object_bag_peek (store->folders, fi->full_name);
 
 	if (folder == NULL
 	    && (flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0)
@@ -185,6 +185,11 @@ fill_fi (CamelStore *store,
 		g_free (folderpath);
 		g_free (path);
 	}
+
+	if (camel_local_store_is_main_store (CAMEL_LOCAL_STORE (store)) && fi->full_name
+	    && (fi->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_NORMAL)
+		fi->flags = (fi->flags & ~CAMEL_FOLDER_TYPE_MASK)
+			    | camel_local_store_get_folder_type_by_full_name (CAMEL_LOCAL_STORE (store), fi->full_name);
 }
 
 static CamelFolderInfo *
diff --git a/camel/providers/local/camel-spool-store.c b/camel/providers/local/camel-spool-store.c
index b30a21e..00fbd2d 100644
--- a/camel/providers/local/camel-spool-store.c
+++ b/camel/providers/local/camel-spool-store.c
@@ -53,7 +53,7 @@ spool_fill_fi (CamelStore *store,
 
 	fi->unread = -1;
 	fi->total = -1;
-	folder = camel_object_bag_get (store->folders, fi->full_name);
+	folder = camel_object_bag_peek (store->folders, fi->full_name);
 	if (folder) {
 		if ((flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0)
 			camel_folder_refresh_info_sync (folder, cancellable, NULL);
@@ -183,7 +183,7 @@ scan_dir (CamelStore *store,
 				gint isfolder = FALSE;
 
 				/* first, see if we already have it open */
-				folder = camel_object_bag_get (store->folders, fname);
+				folder = camel_object_bag_peek (store->folders, fname);
 				if (folder == NULL) {
 					fp = fopen(tmp, "r");
 					if (fp != NULL) {



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