[evolution-data-server] Bug 786982 - After pressing "NOT JUNK" mail stays in the Junk folder
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug 786982 - After pressing "NOT JUNK" mail stays in the Junk folder
- Date: Mon, 11 Sep 2017 14:22:11 +0000 (UTC)
commit 241fcf4d081a0f2d877f8003f7bdc209a5371e82
Author: Milan Crha <mcrha redhat com>
Date: Mon Sep 11 16:22:44 2017 +0200
Bug 786982 - After pressing "NOT JUNK" mail stays in the Junk folder
.../providers/imapx/camel-imapx-conn-manager.c | 83 ++++++++++++++++++++
src/camel/providers/imapx/camel-imapx-folder.c | 60 ++++++++++++++
src/camel/providers/imapx/camel-imapx-folder.h | 6 ++
src/camel/providers/imapx/camel-imapx-server.c | 32 ++++++++
4 files changed, 181 insertions(+), 0 deletions(-)
---
diff --git a/src/camel/providers/imapx/camel-imapx-conn-manager.c
b/src/camel/providers/imapx/camel-imapx-conn-manager.c
index c01011b..a439c87 100644
--- a/src/camel/providers/imapx/camel-imapx-conn-manager.c
+++ b/src/camel/providers/imapx/camel-imapx-conn-manager.c
@@ -1675,6 +1675,14 @@ imapx_conn_manager_move_to_real_trash_sync (CamelIMAPXConnManager *conn_man,
}
g_object_unref (settings);
+ if (!uids_to_copy->len) {
+ g_ptr_array_unref (uids_to_copy);
+ g_clear_object (&mailbox);
+ g_free (real_trash_path);
+
+ return TRUE;
+ }
+
imapx_store = camel_imapx_conn_manager_ref_store (conn_man);
if (real_trash_path != NULL) {
@@ -1735,6 +1743,74 @@ imapx_conn_manager_move_to_real_trash_sync (CamelIMAPXConnManager *conn_man,
}
static gboolean
+imapx_conn_manager_move_to_inbox_sync (CamelIMAPXConnManager *conn_man,
+ CamelFolder *folder,
+ GCancellable *cancellable,
+ gboolean *out_need_to_expunge,
+ GError **error)
+{
+ CamelIMAPXFolder *imapx_folder;
+ CamelIMAPXMailbox *mailbox;
+ GPtrArray *uids_to_copy;
+ gboolean success = TRUE;
+
+ *out_need_to_expunge = FALSE;
+
+ /* Caller already obtained the mailbox from the folder,
+ * so the folder should still have it readily available. */
+ imapx_folder = CAMEL_IMAPX_FOLDER (folder);
+ mailbox = camel_imapx_folder_ref_mailbox (imapx_folder);
+ g_return_val_if_fail (mailbox != NULL, FALSE);
+
+ uids_to_copy = g_ptr_array_new_with_free_func ((GDestroyNotify) camel_pstring_free);
+
+ camel_imapx_folder_claim_move_to_inbox_uids (CAMEL_IMAPX_FOLDER (folder), uids_to_copy);
+
+ if (uids_to_copy->len > 0) {
+ CamelIMAPXStore *imapx_store;
+ CamelIMAPXMailbox *destination = NULL;
+
+ imapx_store = camel_imapx_conn_manager_ref_store (conn_man);
+
+ folder = camel_store_get_inbox_folder_sync (CAMEL_STORE (imapx_store), cancellable, error);
+
+ if (folder != NULL) {
+ destination = camel_imapx_folder_list_mailbox (CAMEL_IMAPX_FOLDER (folder),
cancellable, error);
+ g_object_unref (folder);
+ }
+
+ /* Avoid duplicating messages in the Inbox folder. */
+ if (destination == mailbox) {
+ success = TRUE;
+ } else if (destination != NULL) {
+ if (uids_to_copy->len > 0) {
+ success = imapx_conn_manager_copy_message_sync (
+ conn_man, mailbox, destination,
+ uids_to_copy, TRUE, TRUE, TRUE,
+ cancellable, error);
+ *out_need_to_expunge = success;
+ }
+ } else if (uids_to_copy->len > 0) {
+ success = FALSE;
+ }
+
+ if (!success) {
+ g_prefix_error (
+ error, "%s: ",
+ _("Unable to move messages to Inbox"));
+ }
+
+ g_clear_object (&imapx_store);
+ g_clear_object (&destination);
+ }
+
+ g_ptr_array_unref (uids_to_copy);
+ g_clear_object (&mailbox);
+
+ return success;
+}
+
+static gboolean
imapx_conn_manager_expunge_sync (CamelIMAPXConnManager *conn_man,
CamelIMAPXMailbox *mailbox,
gboolean skip_sync_changes,
@@ -1834,6 +1910,13 @@ camel_imapx_conn_manager_sync_changes_sync (CamelIMAPXConnManager *conn_man,
expunge |= need_to_expunge;
}
+ if (success) {
+ success = imapx_conn_manager_move_to_inbox_sync (
+ conn_man, folder, cancellable,
+ &need_to_expunge, error);
+ expunge |= need_to_expunge;
+ }
+
if (success && expunge) {
job = camel_imapx_job_new (CAMEL_IMAPX_JOB_SYNC_CHANGES, mailbox,
imapx_conn_manager_sync_changes_run_sync,
diff --git a/src/camel/providers/imapx/camel-imapx-folder.c b/src/camel/providers/imapx/camel-imapx-folder.c
index ff6022f..f1f83dc 100644
--- a/src/camel/providers/imapx/camel-imapx-folder.c
+++ b/src/camel/providers/imapx/camel-imapx-folder.c
@@ -47,6 +47,7 @@ struct _CamelIMAPXFolderPrivate {
GMutex move_to_hash_table_lock;
GHashTable *move_to_real_junk_uids;
GHashTable *move_to_real_trash_uids;
+ GHashTable *move_to_inbox_uids;
gboolean check_folder;
};
@@ -102,6 +103,25 @@ camel_imapx_folder_claim_move_to_real_trash_uids (CamelIMAPXFolder *folder,
}
}
+void
+camel_imapx_folder_claim_move_to_inbox_uids (CamelIMAPXFolder *folder,
+ GPtrArray *out_uids_to_copy)
+{
+ GList *keys;
+
+ g_mutex_lock (&folder->priv->move_to_hash_table_lock);
+
+ keys = g_hash_table_get_keys (folder->priv->move_to_inbox_uids);
+ g_hash_table_steal_all (folder->priv->move_to_inbox_uids);
+
+ g_mutex_unlock (&folder->priv->move_to_hash_table_lock);
+
+ while (keys != NULL) {
+ g_ptr_array_add (out_uids_to_copy, keys->data);
+ keys = g_list_delete_link (keys, keys);
+ }
+}
+
static gboolean
imapx_folder_get_apply_filters (CamelIMAPXFolder *folder)
{
@@ -229,6 +249,7 @@ imapx_folder_finalize (GObject *object)
g_mutex_clear (&folder->priv->move_to_hash_table_lock);
g_hash_table_destroy (folder->priv->move_to_real_junk_uids);
g_hash_table_destroy (folder->priv->move_to_real_trash_uids);
+ g_hash_table_destroy (folder->priv->move_to_inbox_uids);
g_weak_ref_clear (&folder->priv->mailbox);
@@ -893,6 +914,7 @@ imapx_folder_changed (CamelFolder *folder,
g_hash_table_remove (imapx_folder->priv->move_to_real_trash_uids, message_uid);
g_hash_table_remove (imapx_folder->priv->move_to_real_junk_uids, message_uid);
+ g_hash_table_remove (imapx_folder->priv->move_to_inbox_uids, message_uid);
camel_data_cache_remove (imapx_folder->cache, "tmp", message_uid, NULL);
camel_data_cache_remove (imapx_folder->cache, "cur", message_uid, NULL);
@@ -1038,6 +1060,7 @@ camel_imapx_folder_init (CamelIMAPXFolder *imapx_folder)
g_mutex_init (&imapx_folder->priv->move_to_hash_table_lock);
imapx_folder->priv->move_to_real_junk_uids = move_to_real_junk_uids;
imapx_folder->priv->move_to_real_trash_uids = move_to_real_trash_uids;
+ imapx_folder->priv->move_to_inbox_uids = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) camel_pstring_free, NULL);
g_mutex_init (&imapx_folder->search_lock);
g_mutex_init (&imapx_folder->stream_lock);
@@ -1405,6 +1428,9 @@ camel_imapx_folder_add_move_to_real_junk (CamelIMAPXFolder *folder,
g_mutex_lock (&folder->priv->move_to_hash_table_lock);
+ g_hash_table_remove (folder->priv->move_to_real_trash_uids, message_uid);
+ g_hash_table_remove (folder->priv->move_to_inbox_uids, message_uid);
+
g_hash_table_add (
folder->priv->move_to_real_junk_uids,
(gpointer) camel_pstring_strdup (message_uid));
@@ -1436,6 +1462,9 @@ camel_imapx_folder_add_move_to_real_trash (CamelIMAPXFolder *folder,
g_mutex_lock (&folder->priv->move_to_hash_table_lock);
+ g_hash_table_remove (folder->priv->move_to_real_junk_uids, message_uid);
+ g_hash_table_remove (folder->priv->move_to_inbox_uids, message_uid);
+
g_hash_table_add (
folder->priv->move_to_real_trash_uids,
(gpointer) camel_pstring_strdup (message_uid));
@@ -1443,6 +1472,37 @@ camel_imapx_folder_add_move_to_real_trash (CamelIMAPXFolder *folder,
g_mutex_unlock (&folder->priv->move_to_hash_table_lock);
}
+/*
+ * camel_imapx_folder_add_move_to_inbox:
+ * @folder: a #CamelIMAPXFolder
+ * @message_uid: a message UID
+ *
+ * Adds @message_uid to a pool of messages to be moved to the Inbox
+ * folder the next time @folder is explicitly synchronized by way of
+ * camel_folder_synchronize() or camel_folder_synchronize_sync().
+ *
+ * Since: 3.28
+ */
+void
+camel_imapx_folder_add_move_to_inbox (CamelIMAPXFolder *folder,
+ const gchar *message_uid)
+{
+ g_return_if_fail (CAMEL_IS_IMAPX_FOLDER (folder));
+ g_return_if_fail (message_uid != NULL);
+ g_return_if_fail (camel_folder_summary_check_uid (camel_folder_get_folder_summary (CAMEL_FOLDER
(folder)), message_uid));
+
+ g_mutex_lock (&folder->priv->move_to_hash_table_lock);
+
+ g_hash_table_remove (folder->priv->move_to_real_trash_uids, message_uid);
+ g_hash_table_remove (folder->priv->move_to_real_junk_uids, message_uid);
+
+ g_hash_table_add (
+ folder->priv->move_to_inbox_uids,
+ (gpointer) camel_pstring_strdup (message_uid));
+
+ g_mutex_unlock (&folder->priv->move_to_hash_table_lock);
+}
+
/**
* camel_imapx_folder_invalidate_local_cache:
* @folder: a #CamelIMAPXFolder
diff --git a/src/camel/providers/imapx/camel-imapx-folder.h b/src/camel/providers/imapx/camel-imapx-folder.h
index 98d4bc0..055fc6b 100644
--- a/src/camel/providers/imapx/camel-imapx-folder.h
+++ b/src/camel/providers/imapx/camel-imapx-folder.h
@@ -91,6 +91,9 @@ void camel_imapx_folder_add_move_to_real_junk
void camel_imapx_folder_add_move_to_real_trash
(CamelIMAPXFolder *folder,
const gchar *message_uid);
+void camel_imapx_folder_add_move_to_inbox
+ (CamelIMAPXFolder *folder,
+ const gchar *message_uid);
void camel_imapx_folder_invalidate_local_cache
(CamelIMAPXFolder *folder,
guint64 new_uidvalidity);
@@ -105,6 +108,9 @@ void camel_imapx_folder_claim_move_to_real_junk_uids
void camel_imapx_folder_claim_move_to_real_trash_uids
(CamelIMAPXFolder *folder,
GPtrArray *out_uids_to_copy);
+void camel_imapx_folder_claim_move_to_inbox_uids
+ (CamelIMAPXFolder *folder,
+ GPtrArray *out_uids_to_copy);
G_END_DECLS
diff --git a/src/camel/providers/imapx/camel-imapx-server.c b/src/camel/providers/imapx/camel-imapx-server.c
index 14a8a51..76a3005 100644
--- a/src/camel/providers/imapx/camel-imapx-server.c
+++ b/src/camel/providers/imapx/camel-imapx-server.c
@@ -5241,6 +5241,7 @@ camel_imapx_server_sync_changes_sync (CamelIMAPXServer *is,
gboolean use_real_junk_path = FALSE;
gboolean use_real_trash_path = FALSE;
gboolean remove_deleted_flags = FALSE;
+ gboolean is_real_junk_folder = FALSE;
gboolean nothing_to_do;
gboolean success;
@@ -5274,7 +5275,27 @@ camel_imapx_server_sync_changes_sync (CamelIMAPXServer *is,
CamelIMAPXSettings *settings;
settings = camel_imapx_server_ref_settings (is);
+
use_real_junk_path = camel_imapx_settings_get_use_real_junk_path (settings);
+ if (use_real_junk_path) {
+ CamelFolder *junk_folder = NULL;
+ gchar *real_junk_path;
+
+ real_junk_path = camel_imapx_settings_dup_real_junk_path (settings);
+ if (real_junk_path) {
+ junk_folder = camel_store_get_folder_sync (
+ camel_folder_get_parent_store (folder),
+ real_junk_path, 0, cancellable, NULL);
+ }
+
+ is_real_junk_folder = junk_folder == folder;
+
+ use_real_junk_path = junk_folder != NULL;
+
+ g_clear_object (&junk_folder);
+ g_free (real_junk_path);
+ }
+
use_real_trash_path = camel_imapx_settings_get_use_real_trash_path (settings);
if (use_real_trash_path) {
CamelFolder *trash_folder = NULL;
@@ -5294,6 +5315,7 @@ camel_imapx_server_sync_changes_sync (CamelIMAPXServer *is,
g_clear_object (&trash_folder);
g_free (real_trash_path);
}
+
g_object_unref (settings);
}
@@ -5334,6 +5356,7 @@ camel_imapx_server_sync_changes_sync (CamelIMAPXServer *is,
if (can_influence_flags) {
gboolean move_to_real_junk;
gboolean move_to_real_trash;
+ gboolean move_to_inbox;
move_to_real_junk =
use_real_junk_path &&
@@ -5343,6 +5366,11 @@ camel_imapx_server_sync_changes_sync (CamelIMAPXServer *is,
use_real_trash_path && remove_deleted_flags &&
(flags & CAMEL_MESSAGE_DELETED);
+ move_to_inbox = is_real_junk_folder &&
+ !move_to_real_junk &&
+ !move_to_real_trash &&
+ (camel_message_info_get_flags (info) & CAMEL_MESSAGE_NOTJUNK) != 0;
+
if (move_to_real_junk)
camel_imapx_folder_add_move_to_real_junk (
CAMEL_IMAPX_FOLDER (folder), uid);
@@ -5350,6 +5378,10 @@ camel_imapx_server_sync_changes_sync (CamelIMAPXServer *is,
if (move_to_real_trash)
camel_imapx_folder_add_move_to_real_trash (
CAMEL_IMAPX_FOLDER (folder), uid);
+
+ if (move_to_inbox)
+ camel_imapx_folder_add_move_to_inbox (
+ CAMEL_IMAPX_FOLDER (folder), uid);
}
if (flags != sflags) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]