[evolution-ews] I#81 - Attachment flag not shown on messages with attachment ][
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] I#81 - Attachment flag not shown on messages with attachment ][
- Date: Fri, 6 Dec 2019 09:27:39 +0000 (UTC)
commit 544ca5fd040c200cc1b7cecc441d7ad2c4051d93
Author: Milan Crha <mcrha redhat com>
Date: Fri Dec 6 10:27:12 2019 +0100
I#81 - Attachment flag not shown on messages with attachment ][
Extends the previous change to:
a) set/unset the attachment flag after the message is loaded from the server;
b) add a guess on common content types to not set the attachment flag in error.
Even if the b) makes it wrong, the a) can correct it later.
Related to https://gitlab.gnome.org/GNOME/evolution-ews/issues/81
src/camel/camel-ews-folder.c | 18 ++++++++++++++++++
src/camel/camel-ews-utils.c | 39 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 56 insertions(+), 1 deletion(-)
---
diff --git a/src/camel/camel-ews-folder.c b/src/camel/camel-ews-folder.c
index 8f6edbd8..a68b7d0c 100644
--- a/src/camel/camel-ews-folder.c
+++ b/src/camel/camel-ews-folder.c
@@ -929,6 +929,7 @@ camel_ews_folder_get_message (CamelFolder *folder,
message = camel_ews_folder_get_message_from_cache (ews_folder, uid, cancellable, error);
if (message) {
CamelInternetAddress *from;
+ CamelMessageInfo *mi;
const gchar *email = NULL, *date_header;
gboolean resave = FALSE;
@@ -999,6 +1000,23 @@ camel_ews_folder_get_message (CamelFolder *folder,
}
g_rec_mutex_unlock (&priv->cache_lock);
}
+
+ mi = camel_folder_summary_get (camel_folder_get_folder_summary (folder), uid);
+ if (mi) {
+ CamelMessageFlags flags;
+ gboolean has_attachment;
+
+ flags = camel_message_info_get_flags (mi);
+ has_attachment = camel_mime_message_has_attachment (message);
+ if (((flags & CAMEL_MESSAGE_ATTACHMENTS) && !has_attachment) ||
+ ((flags & CAMEL_MESSAGE_ATTACHMENTS) == 0 && has_attachment)) {
+ camel_message_info_set_flags (
+ mi, CAMEL_MESSAGE_ATTACHMENTS,
+ has_attachment ? CAMEL_MESSAGE_ATTACHMENTS : 0);
+ }
+
+ g_clear_object (&mi);
+ }
}
exit:
diff --git a/src/camel/camel-ews-utils.c b/src/camel/camel-ews-utils.c
index 7f7a16b0..39224277 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -1044,6 +1044,7 @@ camel_ews_utils_item_to_message_info (CamelEwsFolder *ews_folder,
{
CamelFolderSummary *folder_summary;
CamelMessageInfo *mi = NULL;
+ CamelContentType *content_type = NULL;
const EwsId *id;
const EwsMailbox *from;
gchar *tmp;
@@ -1081,9 +1082,15 @@ camel_ews_utils_item_to_message_info (CamelEwsFolder *ews_folder,
g_object_unref (stream);
if (camel_mime_part_construct_from_parser_sync (part, parser, NULL, NULL)) {
+ CamelContentType *ct;
+
mi = camel_folder_summary_info_new_from_headers (folder_summary,
camel_medium_get_headers (CAMEL_MEDIUM (part)));
if (camel_medium_get_header (CAMEL_MEDIUM (part), "Disposition-Notification-To"))
message_requests_read_receipt = TRUE;
+
+ ct = camel_mime_part_get_content_type (part);
+ if (ct)
+ content_type = camel_content_type_ref (ct);
}
g_object_unref (parser);
@@ -1135,7 +1142,34 @@ camel_ews_utils_item_to_message_info (CamelEwsFolder *ews_folder,
server_flags = ews_utils_get_server_flags (item);
ews_utils_merge_server_user_flags (item, mi);
- camel_message_info_set_flags (mi, server_flags, server_flags);
+ /* It serves as "should inherit CAMEL_MESSAGE_ATTACHMENTS from server_flags" now */
+ has_attachments = !has_attachments;
+
+ if (has_attachments && (server_flags & CAMEL_MESSAGE_ATTACHMENTS) != 0 && content_type) {
+ /* The server can have set the attachment flag, even when there is no attachment.
+ This will be fixed once the message is loaded, but let's fine tune the guess. */
+ if (!camel_content_type_is (content_type, "multipart", "*") ||
+ camel_content_type_is (content_type, "multipart", "alternative")) {
+ has_attachments = FALSE;
+ } else if (camel_content_type_is (content_type, "multipart", "related")) {
+ const gchar *related_type;
+
+ related_type = camel_content_type_param (content_type, "type");
+ if (related_type && *related_type) {
+ CamelContentType *ct;
+
+ ct = camel_content_type_decode (related_type);
+ if (ct) {
+ if (camel_content_type_is (ct, "multipart", "alternative"))
+ has_attachments = FALSE;
+
+ camel_content_type_unref (ct);
+ }
+ }
+ }
+ }
+
+ camel_message_info_set_flags (mi, server_flags & ~(has_attachments ? 0 : CAMEL_MESSAGE_ATTACHMENTS),
server_flags);
camel_ews_message_info_set_server_flags (CAMEL_EWS_MESSAGE_INFO (mi), server_flags);
camel_ews_utils_update_follow_up_flags (item, mi);
@@ -1143,6 +1177,9 @@ camel_ews_utils_item_to_message_info (CamelEwsFolder *ews_folder,
camel_message_info_set_abort_notifications (mi, FALSE);
+ if (content_type)
+ camel_content_type_unref (content_type);
+
return mi;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]