[evolution/gnome-40] I#1491 - Mail: Forwarding e-mail Inline or Quoted duplicates some attachments



commit 4b06d43c02c1bca219f1b35765e544d1e9280bad
Author: Milan Crha <mcrha redhat com>
Date:   Fri May 14 12:47:46 2021 +0200

    I#1491 - Mail: Forwarding e-mail Inline or Quoted duplicates some attachments
    
    For example images can be in the part list twice, once as
    an application/vnd.evolution.attachment and once as a (hidden)
    image itself.
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1491

 src/composer/e-msg-composer.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/src/composer/e-msg-composer.c b/src/composer/e-msg-composer.c
index b38bfc9dfb..b1094a920b 100644
--- a/src/composer/e-msg-composer.c
+++ b/src/composer/e-msg-composer.c
@@ -3271,6 +3271,7 @@ e_msg_composer_add_attachments_from_part_list (EMsgComposer *composer,
                                               gboolean just_inlines)
 {
        EHTMLEditor *editor;
+       GHashTable *added_mime_parts;
        GQueue queue = G_QUEUE_INIT;
        GList *link;
 
@@ -3279,6 +3280,8 @@ e_msg_composer_add_attachments_from_part_list (EMsgComposer *composer,
        if (!part_list)
                return;
 
+       /* One mime part can be in the part list multiple times */
+       added_mime_parts = g_hash_table_new (g_direct_hash, g_direct_equal);
        editor = e_msg_composer_get_editor (composer);
 
        e_mail_part_list_queue_parts (part_list, NULL, &queue);
@@ -3295,9 +3298,16 @@ e_msg_composer_add_attachments_from_part_list (EMsgComposer *composer,
                if (!mime_part)
                        continue;
 
+               if (g_hash_table_contains (added_mime_parts, mime_part)) {
+                       g_object_unref (mime_part);
+                       continue;
+               }
+
                content_type = camel_mime_part_get_content_type (mime_part);
-               if (!content_type)
+               if (!content_type) {
+                       g_object_unref (mime_part);
                        continue;
+               }
 
                if (!just_inlines &&
                    camel_content_type_is (content_type, "text", "*") &&
@@ -3308,8 +3318,10 @@ e_msg_composer_add_attachments_from_part_list (EMsgComposer *composer,
                           camel_mime_part_get_content_id (mime_part) ||
                           camel_mime_part_get_content_location (mime_part))) {
                                e_html_editor_add_cid_part (editor, mime_part);
+                               g_hash_table_add (added_mime_parts, mime_part);
                } else if (!just_inlines) {
                        e_msg_composer_attach (composer, mime_part);
+                       g_hash_table_add (added_mime_parts, mime_part);
                }
 
                g_object_unref (mime_part);
@@ -3317,6 +3329,8 @@ e_msg_composer_add_attachments_from_part_list (EMsgComposer *composer,
 
        while (!g_queue_is_empty (&queue))
                g_object_unref (g_queue_pop_head (&queue));
+
+       g_hash_table_destroy (added_mime_parts);
 }
 
 static void


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