Bug #534369 - New mail notifications for local Inbox don't work
authorMilan Crha <mcrha@redhat.com>
Thu, 14 Oct 2010 11:03:53 +0000 (13:03 +0200)
committerMilan Crha <mcrha@redhat.com>
Thu, 14 Oct 2010 11:03:53 +0000 (13:03 +0200)
camel/providers/local/camel-local-folder.c
camel/providers/local/camel-local-store.c
camel/providers/local/camel-local-store.h
camel/providers/local/camel-maildir-store.c
camel/providers/local/camel-mbox-store.c
camel/providers/local/camel-mh-store.c
camel/providers/local/camel-spool-store.c

index 4d921a6..1a53166 100644 (file)
@@ -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);
index 2984b04..3737bfc 100644 (file)
@@ -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;
+}
index 93f66c0..7198fb9 100644 (file)
@@ -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)))
index ae4291d..0acde10 100644 (file)
@@ -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 {
index e56f075..988af8a 100644 (file)
@@ -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);
 
index 9291f90..7fb31f8 100644 (file)
@@ -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 *
index b30a21e..00fbd2d 100644 (file)
@@ -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) {