aboutsummaryrefslogtreecommitdiffstats
path: root/libemail-engine
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2012-07-09 19:43:16 +0800
committerMatthew Barnes <mbarnes@redhat.com>2012-07-09 20:44:22 +0800
commita0bc647f07e097edf87b89341225710b5be40208 (patch)
tree4fd48c8216ff7c81d822ad1b968903d79775a9b2 /libemail-engine
parentb3d0f3d8ea8691c48e4edfc0436ed43ca12f6ea5 (diff)
downloadgsoc2013-evolution-a0bc647f07e097edf87b89341225710b5be40208.tar.gz
gsoc2013-evolution-a0bc647f07e097edf87b89341225710b5be40208.tar.zst
gsoc2013-evolution-a0bc647f07e097edf87b89341225710b5be40208.zip
Remove mail_expunge_folder().
Use e_mail_folder_expunge() instead.
Diffstat (limited to 'libemail-engine')
-rw-r--r--libemail-engine/mail-ops.c286
-rw-r--r--libemail-engine/mail-ops.h1
2 files changed, 5 insertions, 282 deletions
diff --git a/libemail-engine/mail-ops.c b/libemail-engine/mail-ops.c
index 5543151aef..008de2746a 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 84b4699286..1d9382be52 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 */