Index: camel/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/camel/ChangeLog,v
retrieving revision 1.1310
diff -u -r1.1310 ChangeLog
--- camel/ChangeLog	2001/11/12 23:22:35	1.1310
+++ camel/ChangeLog	2001/11/13 19:36:51
@@ -1,3 +1,19 @@
+2001-11-13    <NotZed@Ximian.com>
+
+	* camel-disco-store.c (set_status): Fix for camel_store_sync api
+	change.
+
+	* providers/imap/camel-imap-store.c (get_folder_info_online): Fix
+	for camel_store_sync api change.
+
+	* camel-store.c (camel_store_sync, store_sync): Added expunge flag
+	& pass to callee.
+	(store_sync): Do exception xfer *after* we've done the sync, der.
+	(store_sync): Use an array instead of a hash table to store the
+	copy of folders.  Partial fix for #13775.
+
+	* camel-store.h: Added expunge flag to store_sync().
+
 2001-11-12  Jeffrey Stedfast  <fejj@ximian.com>
 
 	* camel-store.c (camel_store_get_folder): Added a
Index: camel/camel-disco-store.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-disco-store.c,v
retrieving revision 1.7
diff -u -r1.7 camel-disco-store.c
--- camel/camel-disco-store.c	2001/10/29 18:25:42	1.7
+++ camel/camel-disco-store.c	2001/11/13 19:36:51
@@ -274,7 +274,7 @@
 	if (disco_store->status == status)
 		return;
 
-	camel_store_sync (CAMEL_STORE (disco_store), ex);
+	camel_store_sync (CAMEL_STORE (disco_store), FALSE, ex);
 	if (camel_exception_is_set (ex))
 		return;
 	if (!camel_service_disconnect (CAMEL_SERVICE (disco_store), TRUE, ex))
Index: camel/camel-store.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-store.c,v
retrieving revision 1.100
diff -u -r1.100 camel-store.c
--- camel/camel-store.c	2001/11/12 23:22:36	1.100
+++ camel/camel-store.c	2001/11/13 19:36:51
@@ -60,7 +60,7 @@
 static void rename_folder (CamelStore *store, const char *old_name,
 			   const char *new_name, CamelException *ex);
 
-static void store_sync (CamelStore *store, CamelException *ex);
+static void store_sync (CamelStore *store, int expunge, CamelException *ex);
 static CamelFolderInfo *get_folder_info (CamelStore *store, const char *top,
 					 guint32 flags, CamelException *ex);
 static void free_folder_info (CamelStore *store, CamelFolderInfo *tree);
@@ -605,42 +605,38 @@
 	return folder;
 }
 
-
 static void
-sync_folder (gpointer key, gpointer folder, gpointer ex)
+copy_folder_cache (gpointer key, gpointer folder, gpointer folders)
 {
-	if (!camel_exception_is_set (ex))
-		camel_folder_sync (folder, FALSE, ex);
-	
-	camel_object_unref (CAMEL_OBJECT (folder));
-	g_free (key);
-}
-
-static void
-copy_folder_cache (gpointer key, gpointer folder, gpointer hash)
-{
-	g_hash_table_insert ((GHashTable *) hash, g_strdup (key), folder);
+	g_ptr_array_add((GPtrArray *) folders, folder);
 	camel_object_ref (CAMEL_OBJECT (folder));
 }
 
 static void
-store_sync (CamelStore *store, CamelException *ex)
+store_sync (CamelStore *store, int expunge, CamelException *ex)
 {
 	if (store->folders) {
 		CamelException internal_ex;
-		GHashTable *hash;
-		
-		hash = g_hash_table_new (CS_CLASS (store)->hash_folder_name,
-					 CS_CLASS (store)->compare_folder_name);
-		
-		camel_exception_init (&internal_ex);
+		GPtrArray *folders;
+		int i;
+
+		if (ex == NULL) {
+			camel_exception_init (&internal_ex);
+			ex = &internal_ex;
+		}
+
+		folders = g_ptr_array_new();
 		CAMEL_STORE_LOCK(store, cache_lock);
-		g_hash_table_foreach (store->folders, copy_folder_cache, hash);
+		g_hash_table_foreach (store->folders, copy_folder_cache, folders);
 		CAMEL_STORE_UNLOCK(store, cache_lock);
-		camel_exception_xfer (ex, &internal_ex);
 		
-		g_hash_table_foreach (hash, sync_folder, &internal_ex);
-		g_hash_table_destroy (hash);
+		for (i=0;i<folders->len && !camel_exception_is_set(ex);i++) {
+			CamelFolder *folder = folders->pdata[i];
+
+			camel_folder_sync(folder, expunge, ex);	
+			camel_object_unref(CAMEL_OBJECT (folder));
+		}
+		g_ptr_array_free(folders, TRUE);
 	}
 }
 
@@ -653,11 +649,11 @@
  * folders with the real store.
  **/
 void
-camel_store_sync (CamelStore *store, CamelException *ex)
+camel_store_sync (CamelStore *store, int expunge, CamelException *ex)
 {
 	g_return_if_fail (CAMEL_IS_STORE (store));
 
-	CS_CLASS (store)->sync (store, ex);
+	CS_CLASS (store)->sync (store, expunge, ex);
 }
 
 
Index: camel/camel-store.h
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-store.h,v
retrieving revision 1.53
diff -u -r1.53 camel-store.h
--- camel/camel-store.h	2001/10/28 05:10:54	1.53
+++ camel/camel-store.h	2001/11/13 19:36:51
@@ -125,6 +125,7 @@
 						     CamelException *ex);
 	
 	void            (*sync)                     (CamelStore *store,
+						     int expunge,
 						     CamelException *ex);
 	
 	CamelFolderInfo *(*get_folder_info)         (CamelStore *store,
@@ -171,6 +172,7 @@
 						 CamelException *ex);
 
 void             camel_store_sync               (CamelStore *store,
+						 int expunge,
 						 CamelException *ex);
 
 CamelFolderInfo *camel_store_get_folder_info    (CamelStore *store,
Index: camel/providers/imap/camel-imap-store.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/providers/imap/camel-imap-store.c,v
retrieving revision 1.193
diff -u -r1.193 camel-imap-store.c
--- camel/providers/imap/camel-imap-store.c	2001/11/09 21:48:42	1.193
+++ camel/providers/imap/camel-imap-store.c	2001/11/13 19:36:51
@@ -1592,7 +1592,7 @@
 	/* Get unread counts. Sync flag changes to the server first so
 	 * it has the same ideas about read/unread as we do.
 	 */
-	camel_store_sync (store, NULL);
+	camel_store_sync (store, FALSE, NULL);
 	for (i = 0; i < folders->len; i++) {
 		const char *noselect;
 		CamelURL *url;
Index: mail/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.1940
diff -u -r1.1940 ChangeLog
--- mail/ChangeLog	2001/11/12 23:23:51	1.1940
+++ mail/ChangeLog	2001/11/13 19:36:56
@@ -1,3 +1,11 @@
+2001-11-13    <NotZed@Ximian.com>
+
+	* mail-callbacks.c (empty_trash_expunged_cb): Removed.
+	(empty_trash): Just call sync_store(true) for all stores.  Rest of
+	fix for #13775.
+
+	* mail-ops.c (mail_sync_store): Async sync a store.
+
 2001-11-12  Jeffrey Stedfast  <fejj@ximian.com>
 
 	* mail-vfolder.c (vfolder_load_storage): Add a NULL check for
Index: mail/mail-callbacks.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-callbacks.c,v
retrieving revision 1.282
diff -u -r1.282 mail-callbacks.c
--- mail/mail-callbacks.c	2001/11/11 02:24:45	1.282
+++ mail/mail-callbacks.c	2001/11/13 19:36:56
@@ -2508,59 +2508,20 @@
 }
 
 static void
-empty_trash_expunged_cb (CamelFolder *folder, void *data)
+empty_store(CamelStore *store, void *data, void *user_data)
 {
-	camel_object_unref (CAMEL_OBJECT (folder));
+	mail_sync_store(store, TRUE, NULL, NULL);
 }
 
 void
 empty_trash (BonoboUIComponent *uih, void *user_data, const char *path)
 {
-	MailConfigAccount *account;
-	CamelProvider *provider;
-	const GSList *accounts;
-	CamelFolder *vtrash;
 	FolderBrowser *fb;
-	CamelException ex;
 	
 	fb = user_data ? FOLDER_BROWSER (user_data) : NULL;
 	
 	if (fb && !confirm_expunge (fb))
 		return;
 	
-	camel_exception_init (&ex);
-	
-	/* expunge all remote stores */
-	accounts = mail_config_get_accounts ();
-	while (accounts) {
-		account = accounts->data;
-		
-		/* make sure this is a valid source */
-		if (account->source && account->source->enabled && account->source->url) {
-			provider = camel_session_get_provider (session, account->source->url, &ex);
-			if (provider) {
-				/* make sure this store is a remote store */
-				if (provider->flags & CAMEL_PROVIDER_IS_STORAGE &&
-				    provider->flags & CAMEL_PROVIDER_IS_REMOTE) {
-					vtrash = mail_tool_get_trash (account->source->url, FALSE, &ex);
-					
-					if (vtrash) {
-						mail_expunge_folder (vtrash, empty_trash_expunged_cb, NULL);
-					}
-				}
-			}
-			
-			/* clear the exception for the next round */
-			camel_exception_clear (&ex);
-		}
-		accounts = accounts->next;
-	}
-	
-	/* Now empty the local trash folder */
-	vtrash = mail_tool_get_trash ("file:/", TRUE, &ex);
-	if (vtrash) {
-		mail_expunge_folder (vtrash, empty_trash_expunged_cb, NULL);
-	}
-	
-	camel_exception_clear (&ex);
+	mail_storages_foreach((GHFunc)empty_store, NULL);
 }
Index: mail/mail-ops.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-ops.c,v
retrieving revision 1.348
diff -u -r1.348 mail-ops.c
--- mail/mail-ops.c	2001/10/30 05:02:49	1.348
+++ mail/mail-ops.c	2001/11/13 19:36:56
@@ -1588,6 +1588,70 @@
 	e_thread_put(mail_thread_queued, (EMsg *)m);
 }
 
+/* ** SYNC STORE ********************************************************* */
+
+struct _sync_store_msg {
+	struct _mail_msg msg;
+
+	CamelStore *store;
+	int expunge;
+	void (*done) (CamelStore *store, void *data);
+	void *data;
+};
+
+static char *sync_store_desc(struct _mail_msg *mm, int done)
+{
+	struct _sync_store_msg *m = (struct _sync_store_msg *)mm;
+
+	m = m;
+
+	return g_strdup_printf (_("Storing folders"));
+}
+
+static void sync_store_sync(struct _mail_msg *mm)
+{
+	struct _sync_store_msg *m = (struct _sync_store_msg *)mm;
+
+	camel_store_sync(m->store, m->expunge, &mm->ex);
+}
+
+static void sync_store_synced(struct _mail_msg *mm)
+{
+	struct _sync_store_msg *m = (struct _sync_store_msg *)mm;
+
+	if (m->done)
+		m->done(m->store, m->data);
+}
+
+static void sync_store_free(struct _mail_msg *mm)
+{
+	struct _sync_store_msg *m = (struct _sync_store_msg *)mm;
+
+	camel_object_unref((CamelObject *)m->store);
+}
+
+static struct _mail_msg_op sync_store_op = {
+	sync_store_desc,
+	sync_store_sync,
+	sync_store_synced,
+	sync_store_free,
+};
+
+void
+mail_sync_store(CamelStore *store, int expunge, void (*done) (CamelStore *store, void *data), void *data)
+{
+	struct _sync_store_msg *m;
+
+	m = mail_msg_new(&sync_store_op, NULL, sizeof(*m));
+	m->store = store;
+	camel_object_ref((CamelObject *)store);
+	m->expunge = expunge;
+	m->data = data;
+	m->done = done;
+
+	e_thread_put(mail_thread_queued, (EMsg *)m);
+}
+
 /* ** GET MESSAGE(s) ***************************************************** */
 
 struct _get_message_msg {
Index: mail/mail-ops.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-ops.h,v
retrieving revision 1.50
diff -u -r1.50 mail-ops.h
--- mail/mail-ops.h	2001/10/27 00:47:21	1.50
+++ mail/mail-ops.h	2001/11/13 19:36:56
@@ -87,6 +87,8 @@
 			  void (*done) (CamelFolder *folder, void *data),
 			  void *data);
 
+void mail_sync_store(CamelStore *store, int expunge, void (*done) (CamelStore *store, void *data), void *data);
+
 /* get folder info asynchronously */
 int mail_get_folderinfo (CamelStore *store,
 			 void (*done)(CamelStore *store, CamelFolderInfo *info, void *data),
