[evolution-data-server/gnome-40] IMAPx: Change how Junk and NotJunk flags are handled
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/gnome-40] IMAPx: Change how Junk and NotJunk flags are handled
- Date: Mon, 14 Jun 2021 14:06:50 +0000 (UTC)
commit a201498e34fb4438b8cdbbc5c472821fb87b810f
Author: Milan Crha <mcrha redhat com>
Date: Mon Jun 14 16:03:23 2021 +0200
IMAPx: Change how Junk and NotJunk flags are handled
It can happen that the server fails to unset the Junk flag on the message,
thus the message can end with both Junk and NotJunk flags being set. Treat
this state as the message doesn't have set the Junk flag, thus it'll stay
at its folder, instead of being eventually moved back to the Junk folder.
Related to https://gitlab.gnome.org/GNOME/evolution/-/issues/584
src/camel/providers/imapx/camel-imapx-server.c | 15 ++++++++++++---
src/camel/providers/imapx/camel-imapx-utils.c | 14 ++++++++++++++
2 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/src/camel/providers/imapx/camel-imapx-server.c b/src/camel/providers/imapx/camel-imapx-server.c
index 36e638df9..b8905d072 100644
--- a/src/camel/providers/imapx/camel-imapx-server.c
+++ b/src/camel/providers/imapx/camel-imapx-server.c
@@ -4903,8 +4903,14 @@ camel_imapx_server_copy_message_sync (CamelIMAPXServer *is,
if (remove_deleted_flags)
camel_message_info_set_flags (destination_info,
CAMEL_MESSAGE_DELETED, 0);
- if (remove_junk_flags)
+ if (remove_junk_flags) {
camel_message_info_set_flags (destination_info,
CAMEL_MESSAGE_JUNK, 0);
+
+ /* Force unset of the flag at the destination */
+ camel_imapx_message_info_set_server_flags
(CAMEL_IMAPX_MESSAGE_INFO (destination_info),
+ camel_imapx_message_info_get_server_flags
(CAMEL_IMAPX_MESSAGE_INFO (destination_info)) | CAMEL_MESSAGE_JUNK);
+ camel_message_info_set_folder_flagged
(destination_info, TRUE);
+ }
imapx_copy_move_message_cache (folder, destination_folder,
delete_originals || use_move_command,
camel_message_info_get_uid (source_info),
camel_message_info_get_uid (destination_info),
@@ -5955,9 +5961,12 @@ camel_imapx_server_sync_changes_sync (CamelIMAPXServer *is,
gboolean move_to_real_trash;
gboolean move_to_inbox;
+ /* Some servers can leave the Junk flag even it had been unset, thus check also the
NotJunk flag
+ to avoid move back to the Junk folder. */
move_to_real_junk =
use_real_junk_path &&
- (flags & CAMEL_MESSAGE_JUNK);
+ (flags & CAMEL_MESSAGE_JUNK) &&
+ (camel_message_info_get_flags (info) & CAMEL_MESSAGE_NOTJUNK) == 0;
move_to_real_trash =
use_real_trash_path && remove_deleted_flags &&
@@ -6364,7 +6373,7 @@ camel_imapx_server_sync_changes_sync (CamelIMAPXServer *is,
!(has_flags & CAMEL_MESSAGE_DELETED)) {
set_folder_flagged = FALSE;
} else {
- /* to stare back the \Deleted flag */
+ /* to store back the \Deleted flag */
set_server_flags &= ~CAMEL_MESSAGE_DELETED;
set_folder_flagged = TRUE;
}
diff --git a/src/camel/providers/imapx/camel-imapx-utils.c b/src/camel/providers/imapx/camel-imapx-utils.c
index 9bd729b28..fca9dad5a 100644
--- a/src/camel/providers/imapx/camel-imapx-utils.c
+++ b/src/camel/providers/imapx/camel-imapx-utils.c
@@ -365,6 +365,12 @@ imapx_update_message_info_flags (CamelMessageInfo *info,
if ((permanent_flags & CAMEL_MESSAGE_USER) != 0 && imapx_update_user_flags (info, server_user_flags))
changed = TRUE;
+ /* When both Junk and NotJunk are set, pretend the Junk flag is not set (this can happen when
+ the server fails to unset the Junk flag on message copy/move). */
+ if ((server_flags & CAMEL_MESSAGE_JUNK) != 0 && (server_flags & CAMEL_MESSAGE_NOTJUNK) != 0) {
+ changed = camel_message_info_set_flags (info, CAMEL_MESSAGE_JUNK, 0) || changed;
+ }
+
return changed;
}
@@ -386,6 +392,14 @@ imapx_set_message_info_flags_for_new_message (CamelMessageInfo *info,
camel_message_info_take_user_tags (info, camel_name_value_array_copy (user_tags));
+ /* When the server has set both flags it means the user marked the message as not being junk;
+ in that case pretend the server has the Junk flag off, otherwise the message won't be
+ shown in its destination folder. */
+ if ((server_flags & CAMEL_MESSAGE_JUNK) != 0 &&
+ (server_flags & CAMEL_MESSAGE_NOTJUNK) != 0) {
+ camel_message_info_set_flags (info, CAMEL_MESSAGE_JUNK, 0);
+ }
+
camel_message_info_set_folder_flagged (info, FALSE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]