aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
author0 <NotZed@Ximian.com>2001-09-21 06:59:11 +0800
committerMichael Zucci <zucchi@src.gnome.org>2001-09-21 06:59:11 +0800
commit586f083c3ab79ada76433afbe8529050f2cd5e31 (patch)
tree68dd993b932f67783ded7d00bd3e998ab5804dd2 /mail
parenta6aba35df1c77772c1417354a68a310f90944ced (diff)
downloadgsoc2013-evolution-586f083c3ab79ada76433afbe8529050f2cd5e31.tar
gsoc2013-evolution-586f083c3ab79ada76433afbe8529050f2cd5e31.tar.gz
gsoc2013-evolution-586f083c3ab79ada76433afbe8529050f2cd5e31.tar.bz2
gsoc2013-evolution-586f083c3ab79ada76433afbe8529050f2cd5e31.tar.lz
gsoc2013-evolution-586f083c3ab79ada76433afbe8529050f2cd5e31.tar.xz
gsoc2013-evolution-586f083c3ab79ada76433afbe8529050f2cd5e31.tar.zst
gsoc2013-evolution-586f083c3ab79ada76433afbe8529050f2cd5e31.zip
Lock around hashtable/list manipulation. Also dont try scan vfolder_hash
2001-09-20 <NotZed@Ximian.com> * mail-vfolder.c (vfolder_register_source): Lock around hashtable/list manipulation. Also dont try scan vfolder_hash if it hasn't been setup yet. (source_finalise): Lock around list access. (rule_changed): Lock around hash access. (context_rule_added): Lock around hash access. (context_rule_removed): " (rule_changed): Lock around list access. * mail-local.c (storage_listener_startup): Fix for api change. (local_storage_new_folder_cb): Dont skip over leading / in path. (local_storage_removed_folder_cb): ditto. * mail-folder-cache.c (create_folders): No longer pass prefix between recursive calls - we have the path in the folderinfo. (setup_folder): No longer take path arg, we get it from folderinfo. (mail_note_folder): No longer take path arg, we use folder->full_name to key the folder table. (mail_note_store): Consolidate note_store interface, pass storage or corba_storage to it. (mail_note_local_store): Removed. * mail-ops.c (add_unmatched_info): Scan for unmatched name and re-title. svn path=/trunk/; revision=13023
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog29
-rw-r--r--mail/component-factory.c4
-rw-r--r--mail/mail-folder-cache.c91
-rw-r--r--mail/mail-folder-cache.h14
-rw-r--r--mail/mail-local.c8
-rw-r--r--mail/mail-ops.c27
-rw-r--r--mail/mail-send-recv.c2
-rw-r--r--mail/mail-tools.c2
-rw-r--r--mail/mail-vfolder.c43
9 files changed, 118 insertions, 102 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 831bc4dee0..0c571c7bc8 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,28 @@
+2001-09-20 <NotZed@Ximian.com>
+
+ * mail-vfolder.c (vfolder_register_source): Lock around
+ hashtable/list manipulation. Also dont try scan vfolder_hash if
+ it hasn't been setup yet.
+ (source_finalise): Lock around list access.
+ (rule_changed): Lock around hash access.
+ (context_rule_added): Lock around hash access.
+ (context_rule_removed): "
+ (rule_changed): Lock around list access.
+
+ * mail-local.c (storage_listener_startup): Fix for api change.
+ (local_storage_new_folder_cb): Dont skip over leading / in path.
+ (local_storage_removed_folder_cb): ditto.
+
+ * mail-folder-cache.c (create_folders): No longer pass prefix
+ between recursive calls - we have the path in the folderinfo.
+ (setup_folder): No longer take path arg, we get it from
+ folderinfo.
+ (mail_note_folder): No longer take path arg, we use
+ folder->full_name to key the folder table.
+ (mail_note_store): Consolidate note_store interface, pass storage
+ or corba_storage to it.
+ (mail_note_local_store): Removed.
+
2001-09-20 Jeffrey Stedfast <fejj@ximian.com>
* mail-local.c (mail_local_store_add_folder): Set the folder info
@@ -11,8 +36,8 @@
* folder-browser.c (got_folder): Dont register vfolder sources
here.
- * mail-ops.c (mail_get_folder): Add thread parameter. Fix
- callers.
+ * mail-ops.c (mail_get_folder): Add thread parameter. Fix callers.
+ (add_unmatched_info): Scan for unmatched name and re-title.
* mail-vfolder.c (vfolder_setup): Use the 'slow' queue for setting
up vfolders.
diff --git a/mail/component-factory.c b/mail/component-factory.c
index 6965b004e6..8d656185e3 100644
--- a/mail/component-factory.c
+++ b/mail/component-factory.c
@@ -157,7 +157,7 @@ create_view (EvolutionShellComponent *shell_component,
}
if (!gtk_object_get_data (GTK_OBJECT (storage), "connected"))
- mail_note_store (CAMEL_STORE (store));
+ mail_note_store(CAMEL_STORE(store), storage, CORBA_OBJECT_NIL);
camel_object_unref (CAMEL_OBJECT (store));
control = create_noselect_control ();
@@ -991,7 +991,7 @@ add_storage (const char *name, const char *uri, CamelService *store,
switch (res) {
case EVOLUTION_STORAGE_OK:
mail_hash_storage (store, storage);
- mail_note_store((CamelStore *)store);
+ mail_note_store((CamelStore *)store, storage, CORBA_OBJECT_NIL);
/* falllll */
case EVOLUTION_STORAGE_ERROR_ALREADYREGISTERED:
case EVOLUTION_STORAGE_ERROR_EXISTS:
diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c
index 3921d4a41b..c6e361746f 100644
--- a/mail/mail-folder-cache.c
+++ b/mail/mail-folder-cache.c
@@ -100,7 +100,7 @@ update_1folder(struct _folder_info *mfi, CamelFolderInfo *info)
}
static void
-setup_folder(const char *path, CamelFolderInfo *fi, struct _store_info *si)
+setup_folder(CamelFolderInfo *fi, struct _store_info *si)
{
struct _folder_info *mfi;
char *type;
@@ -113,9 +113,9 @@ setup_folder(const char *path, CamelFolderInfo *fi, struct _store_info *si)
update_1folder(mfi, fi);
} else {
/* always 'add it', but only 'add it' to non-local stores */
- d(printf("Adding new folder: %s (%s)\n", path, fi->url));
+ d(printf("Adding new folder: %s (%s)\n", fi->path, fi->url));
mfi = g_malloc0(sizeof(*mfi));
- mfi->path = g_strdup(path);
+ mfi->path = g_strdup(fi->path);
mfi->name = g_strdup(fi->name);
mfi->full_name = g_strdup(fi->full_name);
mfi->store_info = si;
@@ -124,7 +124,7 @@ setup_folder(const char *path, CamelFolderInfo *fi, struct _store_info *si)
if (si->storage != NULL) {
type = (strncmp(fi->url, "vtrash:", 7)==0)?"vtrash":"mail";
- evolution_storage_new_folder(si->storage, path, mfi->name, type,
+ evolution_storage_new_folder(si->storage, mfi->path, mfi->name, type,
fi->url, mfi->name, unread);
}
}
@@ -160,7 +160,7 @@ folder_finalised(CamelObject *o, gpointer event_data, gpointer user_data)
}
static void
-real_note_folder(CamelFolder *folder, char *path, void *data)
+real_note_folder(CamelFolder *folder, void *event_data, void *data)
{
CamelStore *store = folder->parent_store;
struct _store_info *si;
@@ -170,26 +170,20 @@ real_note_folder(CamelFolder *folder, char *path, void *data)
si = g_hash_table_lookup(stores, store);
UNLOCK(info_lock);
if (si == NULL) {
- g_free(path);
g_warning("Adding a folder `%s' to a store which hasn't been added yet?\n", folder->full_name);
camel_object_unref((CamelObject *)folder);
return;
}
- if (path == NULL)
- path = g_strdup_printf("/%s", folder->full_name);
-
LOCK(info_lock);
mfi = g_hash_table_lookup(si->folders, folder->full_name);
UNLOCK(info_lock);
if (mfi == NULL) {
- g_warning("Adding a folder `%s' that I dont know about yet?\n path='%s'", folder->full_name, path);
- g_free(path);
+ g_warning("Adding a folder `%s' that I dont know about yet?", folder->full_name);
camel_object_unref((CamelObject *)folder);
return;
}
- g_free(path);
/* dont do anything if we already have this */
if (mfi->folder == folder)
@@ -205,42 +199,33 @@ real_note_folder(CamelFolder *folder, char *path, void *data)
camel_object_unref((CamelObject *)folder);
}
-/* supply path if different from folder->full_name? */
-void mail_note_folder(CamelFolder *folder, const char *path)
+void mail_note_folder(CamelFolder *folder)
{
- char *real = NULL;
-
if (stores == NULL) {
g_warning("Adding a folder `%s' to a store which hasn't been added yet?\n", folder->full_name);
return;
}
camel_object_ref((CamelObject *)folder);
- if (path)
- real = g_strdup_printf("/%s", path);
- mail_proxy_event((CamelObjectEventHookFunc)real_note_folder, (CamelObject *)folder, real, NULL);
+ mail_proxy_event((CamelObjectEventHookFunc)real_note_folder, (CamelObject *)folder, NULL, NULL);
}
static void
real_folder_created(CamelStore *store, void *event_data, CamelFolderInfo *fi)
{
struct _store_info *si;
- char *path;
d(printf("real_folder_created: %s (%s)\n", fi->full_name, fi->url));
LOCK(info_lock);
si = g_hash_table_lookup(stores, store);
UNLOCK(info_lock);
- if (si) {
- path = g_strdup_printf("/%s", fi->full_name);
- setup_folder(path, fi, si);
- g_free(path);
- } else {
+ if (si)
+ setup_folder(fi, si);
+ else
/* leaks, so what */
g_warning("real_folder_created: can't find store: %s\n",
camel_url_to_string(((CamelService *)store)->url, 0));
- }
}
static void
@@ -287,7 +272,7 @@ store_finalised(CamelObject *o, void *event_data, void *data)
si = g_hash_table_lookup(stores, store);
if (si) {
g_hash_table_remove(stores, store);
- g_hash_table_foreach(si->folders, free_folder_info, NULL);
+ g_hash_table_foreach(si->folders, (GHFunc)free_folder_info, NULL);
g_hash_table_destroy(si->folders);
g_free(si);
}
@@ -295,20 +280,14 @@ store_finalised(CamelObject *o, void *event_data, void *data)
}
static void
-create_folders(const char *prefix, CamelFolderInfo *fi, struct _store_info *si)
+create_folders(CamelFolderInfo *fi, struct _store_info *si)
{
- char *path;
-
- path = g_strdup_printf ("%s/%s", prefix, fi->name);
- setup_folder(path, fi, si);
+ setup_folder(fi, si);
if (fi->child)
- create_folders(path, fi->child, si);
-
- g_free(path);
-
+ create_folders(fi->child, si);
if (fi->sibling)
- create_folders(prefix, fi->sibling, si);
+ create_folders(fi->sibling, si);
}
static void
@@ -319,15 +298,19 @@ update_folders(CamelStore *store, CamelFolderInfo *info, void *data)
if (info) {
if (si->storage)
gtk_object_set_data (GTK_OBJECT (si->storage), "connected", GINT_TO_POINTER (TRUE));
- create_folders("", info, si);
+ create_folders(info, si);
}
}
-static void
-setup_store(CamelStore *store, EvolutionStorage *storage, GNOME_Evolution_Storage corba_storage)
+void
+mail_note_store(CamelStore *store, EvolutionStorage *storage, GNOME_Evolution_Storage corba_storage)
{
struct _store_info *si;
+ g_assert(CAMEL_IS_STORE(store));
+ g_assert(pthread_self() == mail_gui_thread);
+ g_assert(storage != NULL || corba_storage != CORBA_OBJECT_NIL);
+
LOCK(info_lock);
if (stores == NULL)
@@ -353,31 +336,3 @@ setup_store(CamelStore *store, EvolutionStorage *storage, GNOME_Evolution_Storag
mail_msg_wait(mail_get_folderinfo(store, update_folders, si));
}
-
-
-void mail_note_store(CamelStore *store)
-{
- EvolutionStorage *storage;
- /* i'm not including all the sht in mail.h just for this !*/
- EvolutionStorage *mail_lookup_storage (CamelStore *store);
-
- g_assert(CAMEL_IS_STORE(store));
- g_assert(pthread_self() == mail_gui_thread);
-
- storage = mail_lookup_storage(store);
- if (storage == NULL) {
- g_warning("Trying to monitor a store for which there is no storage: %s",
- camel_url_to_string(((CamelService *)store)->url, 0));
- return;
- }
-
- setup_store(store, storage, CORBA_OBJECT_NIL);
-}
-
-void mail_note_local_store(CamelStore *store, GNOME_Evolution_Storage corba_storage)
-{
- g_assert(CAMEL_IS_STORE(store));
- g_assert(pthread_self() == mail_gui_thread);
-
- setup_store(store, NULL, corba_storage);
-}
diff --git a/mail/mail-folder-cache.h b/mail/mail-folder-cache.h
index 7aab84d748..1bfdf5066a 100644
--- a/mail/mail-folder-cache.h
+++ b/mail/mail-folder-cache.h
@@ -31,16 +31,12 @@
/* Add a store whose folders should appear in the shell
The folders are scanned from the store, and/or added at
runtime via the folder_created event */
-void mail_note_store(struct _CamelStore *store);
-
-/* Similar to above, but do updates via a local GNOME_Evolutuion_Storage
- rather than a remote proxy EvolutionStorage object */
-void mail_note_local_store(struct _CamelStore *store, GNOME_Evolution_Storage corba_storage);
+void mail_note_store(struct _CamelStore *store, struct _EvolutionStorage *storage, GNOME_Evolution_Storage corba_storage);
/* When a folder has been opened, notify it for watching.
- The path may be NULL if the shell-equivalent path can be determined
- from the folder->full_name, if it cannot, then the path must
- be supplied */
-void mail_note_folder(struct _CamelFolder *folder, const char *path);
+ The folder must have already been created on the store (which has already been noted)
+ before the folder can be opened
+ */
+void mail_note_folder(struct _CamelFolder *folder);
#endif
diff --git a/mail/mail-local.c b/mail/mail-local.c
index ddbdc26c2e..20562d83dd 100644
--- a/mail/mail-local.c
+++ b/mail/mail-local.c
@@ -938,9 +938,6 @@ local_storage_new_folder_cb (EvolutionStorageListener *storage_listener,
if (strcmp (folder->type, "mail") != 0)
return;
- if (path[0] == '/')
- path++;
-
d(printf("Local folder new:\n"));
d(printf(" path = '%s'\n uri = '%s'\n display = '%s'\n",
path, folder->physicalUri, folder->displayName));
@@ -956,9 +953,6 @@ local_storage_removed_folder_cb (EvolutionStorageListener *storage_listener,
const char *path,
void *data)
{
- if (path[0] == '/')
- path++;
-
d(printf("Local folder remove:\n"));
d(printf(" path = '%s'\n", path));
@@ -982,7 +976,7 @@ storage_listener_startup (EvolutionShellClient *shellclient)
}
/* setup to record this store's changes */
- mail_note_local_store((CamelStore *)global_local_store, local_corba_storage);
+ mail_note_store((CamelStore *)global_local_store, NULL, local_corba_storage);
local_storage_listener = evolution_storage_listener_new ();
corba_local_storage_listener = evolution_storage_listener_corba_objref (
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index a29f19a896..a9f300baad 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -36,6 +36,7 @@
#include <camel/camel-mime-filter-from.h>
#include <camel/camel-operation.h>
#include <camel/camel-vtrash-folder.h>
+#include <camel/camel-vee-store.h>
#include "mail.h"
#include "mail-tools.h"
#include "mail-ops.h"
@@ -1097,13 +1098,29 @@ add_vtrash_info (CamelStore *store, CamelFolderInfo *info)
/* Fill in the new fields */
vtrash->full_name = g_strdup (U_("Trash"));
- vtrash->name = g_strdup (U_("Trash"));
+ vtrash->name = g_strdup(vtrash->full_name);
vtrash->url = g_strdup_printf ("vtrash:%s", uri);
vtrash->unread_message_count = -1;
+ vtrash->path = g_strdup_printf("/%s", vtrash->name);
g_free (uri);
}
static void
+add_unmatched_info(CamelFolderInfo *fi)
+{
+ for (; fi->sibling; fi = fi->sibling) {
+ if (!strcmp(fi->full_name, CAMEL_UNMATCHED_NAME)) {
+ printf("renaming unmatched!\n");
+ g_free(fi->name);
+ fi->name = g_strdup(U_("Unmatched"));
+ g_free(fi->path);
+ fi->path = g_strdup_printf("/%s", fi->name);
+ break;
+ }
+ }
+}
+
+static void
get_folderinfo_get (struct _mail_msg *mm)
{
struct _get_folderinfo_msg *m = (struct _get_folderinfo_msg *)mm;
@@ -1113,8 +1130,12 @@ get_folderinfo_get (struct _mail_msg *mm)
flags |= CAMEL_STORE_FOLDER_INFO_SUBSCRIBED;
m->info = camel_store_get_folder_info (m->store, NULL, flags, &mm->ex);
- if (m->info && m->info->url && (m->store->flags & CAMEL_STORE_VTRASH))
- add_vtrash_info (m->store, m->info);
+ if (m->info) {
+ if (m->info->url && (m->store->flags & CAMEL_STORE_VTRASH))
+ add_vtrash_info(m->store, m->info);
+ if (CAMEL_IS_VEE_STORE(m->store))
+ add_unmatched_info(m->info);
+ }
}
static void
diff --git a/mail/mail-send-recv.c b/mail/mail-send-recv.c
index c1938eafb7..fff2332749 100644
--- a/mail/mail-send-recv.c
+++ b/mail/mail-send-recv.c
@@ -602,7 +602,7 @@ receive_update_got_store (char *uri, CamelStore *store, void *data)
if (storage) {
if (!gtk_object_get_data (GTK_OBJECT (storage), "connected"))
- mail_note_store (store);
+ mail_note_store(store, storage, CORBA_OBJECT_NIL);
mail_update_subfolders (store, storage, receive_update_done, info);
bonobo_object_unref (BONOBO_OBJECT (storage));
diff --git a/mail/mail-tools.c b/mail/mail-tools.c
index 830ca4c613..250e7c2f06 100644
--- a/mail/mail-tools.c
+++ b/mail/mail-tools.c
@@ -367,7 +367,7 @@ mail_tool_uri_to_folder (const char *uri, CamelException *ex)
}
} else {
vfolder_register_source(folder);
- mail_note_folder(folder, NULL);
+ mail_note_folder(folder);
}
camel_url_free (url);
diff --git a/mail/mail-vfolder.c b/mail/mail-vfolder.c
index c5dec4fb64..13da061abc 100644
--- a/mail/mail-vfolder.c
+++ b/mail/mail-vfolder.c
@@ -46,12 +46,17 @@ struct _vfolder_info {
};
/* list of vfolders available */
-static VfolderContext *context;
-static CamelStore *vfolder_store;
-static GList *source_folders; /* list of source folders */
+static VfolderContext *context; /* context remains open all time */
+static CamelStore *vfolder_store; /* the 1 static vfolder store */
+
+/* lock for accessing shared resources (below) */
+static pthread_mutex_t vfolder_lock = PTHREAD_MUTEX_INITIALIZER;
+
+static GList *source_folders; /* list of source folders */
static GHashTable *vfolder_hash;
+
/* Ditto below */
EvolutionStorage *vfolder_storage;
@@ -61,6 +66,9 @@ extern EvolutionShellClient *global_shell_client;
extern char *evolution_dir;
extern CamelSession *session;
+#define LOCK() pthread_mutex_lock(&vfolder_lock);
+#define UNLOCK() pthread_mutex_unlock(&vfolder_lock);
+
/* ********************************************************************** */
/* return true if this folder should be added to this rule */
@@ -100,7 +108,9 @@ register_source(char *key, CamelVeeFolder *vfolder, CamelFolder *folder)
static void
source_finalise(CamelFolder *folder, void *event_data, void *data)
{
+ LOCK();
source_folders = g_list_remove(source_folders, folder);
+ UNLOCK();
}
/* for registering potential vfolder sources */
@@ -109,9 +119,12 @@ vfolder_register_source (CamelFolder *folder)
{
if (CAMEL_IS_VEE_FOLDER(folder))
return;
-
- if (g_list_find(source_folders, folder))
+
+ LOCK();
+ if (g_list_find(source_folders, folder)) {
+ UNLOCK();
return;
+ }
/* note that once we register a source, it will be ref'd
by our vfolder ... and wont go away with this, but we
@@ -119,7 +132,9 @@ vfolder_register_source (CamelFolder *folder)
camel_object_hook_event((CamelObject *)folder, "finalize", (CamelObjectEventHookFunc)source_finalise, folder);
source_folders = g_list_append(source_folders, folder);
- g_hash_table_foreach(vfolder_hash, (GHFunc)register_source, folder);
+ if (vfolder_hash)
+ g_hash_table_foreach(vfolder_hash, (GHFunc)register_source, folder);
+ UNLOCK();
}
/* ********************************************************************** */
@@ -266,11 +281,14 @@ rule_changed(FilterRule *rule, CamelFolder *folder)
evolution_storage_removed_folder(mail_lookup_storage(vfolder_store), path);
g_free(path);
+ LOCK();
if (g_hash_table_lookup_extended(vfolder_hash, folder->full_name, (void **)&key, (void **)&old)) {
g_hash_table_remove(vfolder_hash, key);
g_free(key);
+ UNLOCK();
camel_object_unref((CamelObject *)folder);
} else {
+ UNLOCK();
g_warning("couldn't find a vfolder rule in our table? %s", folder->full_name);
}
@@ -284,7 +302,8 @@ rule_changed(FilterRule *rule, CamelFolder *folder)
while ( (sourceuri = vfolder_rule_next_source((VfolderRule *)rule, sourceuri)) ) {
sources_uri = g_list_append(sources_uri, g_strdup(sourceuri));
}
-
+
+ LOCK();
l = source_folders;
while (l) {
if (check_source(rule, l->data)) {
@@ -293,6 +312,7 @@ rule_changed(FilterRule *rule, CamelFolder *folder)
}
l = l->next;
}
+ UNLOCK();
query = g_string_new("");
filter_rule_build_code(rule, query);
@@ -313,9 +333,11 @@ static void context_rule_added(RuleContext *ctx, FilterRule *rule)
if (folder) {
gtk_signal_connect((GtkObject *)rule, "changed", rule_changed, folder);
+ LOCK();
g_hash_table_insert(vfolder_hash, g_strdup(rule->name), folder);
+ UNLOCK();
- mail_note_folder(folder, NULL);
+ mail_note_folder(folder);
rule_changed(rule, folder);
}
}
@@ -333,11 +355,14 @@ static void context_rule_removed(RuleContext *ctx, FilterRule *rule)
evolution_storage_removed_folder(mail_lookup_storage(vfolder_store), path);
g_free(path);
+ LOCK();
if (g_hash_table_lookup_extended(vfolder_hash, rule->name, (void **)&key, (void **)&folder)) {
g_hash_table_remove(vfolder_hash, key);
g_free(key);
+ UNLOCK();
camel_object_unref((CamelObject *)folder);
- }
+ } else
+ UNLOCK();
camel_store_delete_folder(vfolder_store, rule->name, NULL);
}