[evolution] Remove mail_expunge_folder().



commit a0bc647f07e097edf87b89341225710b5be40208
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Jul 9 07:43:16 2012 -0400

    Remove mail_expunge_folder().
    
    Use e_mail_folder_expunge() instead.

 libemail-engine/mail-ops.c               |  286 +-----------------------------
 libemail-engine/mail-ops.h               |    1 -
 modules/mail/e-mail-shell-view-actions.c |   39 ++---
 3 files changed, 23 insertions(+), 303 deletions(-)
---
diff --git a/libemail-engine/mail-ops.c b/libemail-engine/mail-ops.c
index 5543151..008de27 100644
--- a/libemail-engine/mail-ops.c
+++ b/libemail-engine/mail-ops.c
@@ -42,6 +42,7 @@
 #include "mail-ops.h"
 #include "mail-tools.h"
 
+#include "e-mail-folder-utils.h"
 #include "e-mail-session.h"
 #include "e-mail-session-utils.h"
 
@@ -1325,273 +1326,6 @@ mail_sync_store (CamelStore *store,
 
 /* ******************************************************************************** */
 
-static gboolean
-folder_is_from_source_uid (CamelFolder *folder,
-                           const gchar *source_uid)
-{
-	CamelStore *store;
-	const gchar *uid;
-
-	store = camel_folder_get_parent_store (folder);
-	uid = camel_service_get_uid (CAMEL_SERVICE (store));
-
-	return (g_strcmp0 (uid, source_uid) == 0);
-}
-
-/* This is because pop3 accounts are hidden under local Inbox,
- * thus whenever an expunge is done on a local trash or Inbox,
- * then also all active pop3 accounts should be expunged. */
-static gboolean
-expunge_pop3_stores (CamelFolder *expunging,
-                     GCancellable *cancellable,
-                     GError **error)
-{
-	GHashTable *expunging_uids;
-	CamelStore *parent_store;
-	CamelService *service;
-	CamelSession *session;
-	ESourceRegistry *registry;
-	GPtrArray *uids;
-	GList *list, *link;
-	const gchar *extension_name;
-	gboolean success = TRUE;
-	guint ii;
-
-	parent_store = camel_folder_get_parent_store (expunging);
-
-	service = CAMEL_SERVICE (parent_store);
-	session = camel_service_get_session (service);
-	registry = e_mail_session_get_registry (E_MAIL_SESSION (session));
-
-	uids = camel_folder_get_uids (expunging);
-
-	if (uids == NULL)
-		return TRUE;
-
-	expunging_uids = g_hash_table_new_full (
-		(GHashFunc) g_str_hash,
-		(GEqualFunc) g_str_equal,
-		(GDestroyNotify) g_free,
-		(GDestroyNotify) g_free);
-
-	for (ii = 0; ii < uids->len; ii++) {
-		CamelMessageInfo *info;
-		CamelMessageFlags flags = 0;
-		CamelMimeMessage *message;
-		const gchar *pop3_uid;
-		const gchar *source_uid;
-
-		info = camel_folder_get_message_info (
-			expunging, uids->pdata[ii]);
-
-		if (info != NULL) {
-			flags = camel_message_info_flags (info);
-			camel_folder_free_message_info (expunging, info);
-		}
-
-		/* Only interested in deleted messages. */
-		if ((flags & CAMEL_MESSAGE_DELETED) == 0)
-			continue;
-
-		/* because the UID in the local store doesn't
-		 * match with the UID in the pop3 store */
-		message = camel_folder_get_message_sync (
-			expunging, uids->pdata[ii], cancellable, NULL);
-
-		if (message == NULL)
-			continue;
-
-		pop3_uid = camel_medium_get_header (
-			CAMEL_MEDIUM (message), "X-Evolution-POP3-UID");
-		source_uid = camel_mime_message_get_source (message);
-
-		if (pop3_uid != NULL)
-			g_hash_table_insert (
-				expunging_uids,
-				g_strstrip (g_strdup (pop3_uid)),
-				g_strstrip (g_strdup (source_uid)));
-
-		g_object_unref (message);
-	}
-
-	camel_folder_free_uids (expunging, uids);
-	uids = NULL;
-
-	if (g_hash_table_size (expunging_uids) == 0) {
-		g_hash_table_destroy (expunging_uids);
-		return TRUE;
-	}
-
-	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
-	list = e_source_registry_list_sources (registry, extension_name);
-
-	for (link = list; link != NULL; link = g_list_next (link)) {
-		ESource *source = E_SOURCE (link->data);
-		ESourceBackend *extension;
-		CamelFolder *folder;
-		CamelService *service;
-		CamelSettings *settings;
-		const gchar *backend_name;
-		const gchar *source_uid;
-		gboolean any_found = FALSE;
-		gboolean delete_expunged = FALSE;
-		gboolean keep_on_server = FALSE;
-		gboolean enabled;
-
-		source_uid = e_source_get_uid (source);
-		enabled = e_source_get_enabled (source);
-
-		extension = e_source_get_extension (source, extension_name);
-		backend_name = e_source_backend_get_backend_name (extension);
-
-		if (!enabled || g_strcmp0 (backend_name, "pop") != 0)
-			continue;
-
-		service = camel_session_get_service (
-			CAMEL_SESSION (session), source_uid);
-
-		settings = camel_service_get_settings (service);
-
-		g_object_get (
-			settings,
-			"delete-expunged", &delete_expunged,
-			"keep-on-server", &keep_on_server,
-			NULL);
-
-		if (!keep_on_server || !delete_expunged)
-			continue;
-
-		folder = camel_store_get_inbox_folder_sync (
-			CAMEL_STORE (service), cancellable, error);
-
-		/* Abort the loop on error. */
-		if (folder == NULL) {
-			success = FALSE;
-			break;
-		}
-
-		uids = camel_folder_get_uids (folder);
-
-		if (uids == NULL) {
-			g_object_unref (folder);
-			continue;
-		}
-
-		for (ii = 0; ii < uids->len; ii++) {
-			/* ensure the ID is from this account,
-			 * as it's generated by evolution */
-			const gchar *source_uid;
-
-			source_uid = g_hash_table_lookup (
-				expunging_uids, uids->pdata[ii]);
-			if (folder_is_from_source_uid (folder, source_uid)) {
-				any_found = TRUE;
-				camel_folder_delete_message (
-					folder, uids->pdata[ii]);
-			}
-		}
-
-		camel_folder_free_uids (folder, uids);
-
-		if (any_found)
-			success = camel_folder_synchronize_sync (
-				folder, TRUE, cancellable, error);
-
-		g_object_unref (folder);
-
-		/* Abort the loop on error. */
-		if (!success)
-			break;
-	}
-
-	g_list_free_full (list, (GDestroyNotify) g_object_unref);
-
-	g_hash_table_destroy (expunging_uids);
-
-	return success;
-}
-
-static gchar *
-expunge_folder_desc (struct _sync_folder_msg *m)
-{
-	return g_strdup_printf (
-		_("Expunging folder '%s'"),
-		camel_folder_get_full_name (m->folder));
-}
-
-static void
-expunge_folder_exec (struct _sync_folder_msg *m,
-                     GCancellable *cancellable,
-                     GError **error)
-{
-	CamelFolder *local_inbox;
-	CamelStore *parent_store;
-	CamelService *service;
-	CamelSession *session;
-	gboolean is_local_inbox_or_trash;
-	gboolean store_is_local;
-	gboolean success = TRUE;
-	const gchar *uid;
-
-	parent_store = camel_folder_get_parent_store (m->folder);
-
-	service = CAMEL_SERVICE (parent_store);
-	session = camel_service_get_session (service);
-
-	uid = camel_service_get_uid (service);
-	store_is_local = (g_strcmp0 (uid, E_MAIL_SESSION_LOCAL_UID) == 0);
-
-	local_inbox =
-		e_mail_session_get_local_folder (
-		E_MAIL_SESSION (session), E_MAIL_LOCAL_FOLDER_INBOX);
-	is_local_inbox_or_trash = (m->folder == local_inbox);
-
-	if (store_is_local && !is_local_inbox_or_trash) {
-		CamelFolder *trash;
-
-		trash = camel_store_get_trash_folder_sync (
-			parent_store, cancellable, error);
-
-		if (trash == NULL)
-			return;
-
-		is_local_inbox_or_trash = (m->folder == trash);
-
-		g_object_unref (trash);
-	}
-
-	/* do this before expunge, to know which messages will be expunged */
-	if (is_local_inbox_or_trash)
-		success = expunge_pop3_stores (m->folder, cancellable, error);
-
-	if (success)
-		camel_folder_expunge_sync (m->folder, cancellable, error);
-}
-
-/* we just use the sync stuff where we can, since it would be the same */
-static MailMsgInfo expunge_folder_info = {
-	sizeof (struct _sync_folder_msg),
-	(MailMsgDescFunc) expunge_folder_desc,
-	(MailMsgExecFunc) expunge_folder_exec,
-	(MailMsgDoneFunc) sync_folder_done,
-	(MailMsgFreeFunc) sync_folder_free
-};
-
-void
-mail_expunge_folder (CamelFolder *folder)
-{
-	struct _sync_folder_msg *m;
-
-	g_return_if_fail (CAMEL_IS_FOLDER (folder));
-
-	m = mail_msg_new (&expunge_folder_info);
-	m->folder = g_object_ref (folder);
-
-	mail_msg_slow_ordered_push (m);
-}
-
-/* ******************************************************************************** */
-
 struct _empty_trash_msg {
 	MailMsg base;
 
@@ -1618,11 +1352,8 @@ empty_trash_exec (struct _empty_trash_msg *m,
 {
 	CamelService *service;
 	CamelFolder *trash;
-	const gchar *uid;
-	gboolean success = TRUE;
 
 	service = CAMEL_SERVICE (m->store);
-	uid = camel_service_get_uid (service);
 
 	if (!camel_service_connect_sync (service, cancellable, error))
 		return;
@@ -1630,17 +1361,10 @@ empty_trash_exec (struct _empty_trash_msg *m,
 	trash = camel_store_get_trash_folder_sync (
 		m->store, cancellable, error);
 
-	if (trash == NULL)
-		return;
-
-	/* do this before expunge, to know which messages will be expunged */
-	if (g_strcmp0 (uid, E_MAIL_SESSION_LOCAL_UID) == 0)
-		success = expunge_pop3_stores (trash, cancellable, error);
-
-	if (success)
-		camel_folder_expunge_sync (trash, cancellable, error);
-
-	g_object_unref (trash);
+	if (trash != NULL) {
+		e_mail_folder_expunge_sync (trash, cancellable, error);
+		g_object_unref (trash);
+	}
 }
 
 static void
diff --git a/libemail-engine/mail-ops.h b/libemail-engine/mail-ops.h
index 84b4699..1d9382b 100644
--- a/libemail-engine/mail-ops.h
+++ b/libemail-engine/mail-ops.h
@@ -45,7 +45,6 @@ void mail_sync_folder (CamelFolder *folder,
 void mail_sync_store (CamelStore *store, gint expunge,
 		     void (*done) (CamelStore *store, gpointer data), gpointer data);
 
-void		mail_expunge_folder		(CamelFolder *folder);
 void		mail_empty_trash		(CamelStore *store);
 
 /* transfer (copy/move) a folder */
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c
index 3d39c4f..e6cd01d 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -330,41 +330,38 @@ static void
 action_mail_folder_expunge_cb (GtkAction *action,
                                EMailShellView *mail_shell_view)
 {
+	EMailShellContent *mail_shell_content;
 	EMailShellSidebar *mail_shell_sidebar;
+	EMailView *mail_view;
 	EMFolderTree *folder_tree;
-	EShellWindow *shell_window;
-	EShellView *shell_view;
-	CamelFolder *folder;
-	const gchar *description;
-	gboolean proceed;
+	CamelStore *selected_store = NULL;
+	gchar *selected_folder_name = NULL;
 
 	/* This handles both the "folder-expunge" and "account-expunge"
 	 * actions. */
 
-	shell_view = E_SHELL_VIEW (mail_shell_view);
-	shell_window = e_shell_view_get_shell_window (shell_view);
+	mail_shell_content = mail_shell_view->priv->mail_shell_content;
+	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
+
+	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
+	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
 
 	/* Get the folder from the folder tree, not the message list.
 	 * This correctly handles the use case of right-clicking on
 	 * the "Trash" folder and selecting "Empty Trash" without
 	 * actually selecting the folder.  In that case the message
 	 * list would not contain the correct folder to expunge. */
+	em_folder_tree_get_selected (
+		folder_tree, &selected_store, &selected_folder_name);
+	g_return_if_fail (CAMEL_IS_STORE (selected_store));
+	g_return_if_fail (selected_folder_name != NULL);
 
-	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
-	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);
-	folder = em_folder_tree_get_selected_folder (folder_tree);
-	g_return_if_fail (folder != NULL);
-
-	description = camel_folder_get_description (folder);
-
-	proceed = em_utils_prompt_user (
-		GTK_WINDOW (shell_window),
-		"prompt-on-expunge",
-		"mail:ask-expunge",
-		description, NULL);
+	e_mail_reader_expunge_folder_name (
+		E_MAIL_READER (mail_view),
+		selected_store, selected_folder_name);
 
-	if (proceed)
-		mail_expunge_folder (folder);
+	g_object_unref (selected_store);
+	g_free (selected_folder_name);
 }
 
 static void



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