[evolution] I#1653 - Correct Edit as New Message inside a Search Folder



commit 0c4c8906ca68fe1250376163997e6391562f6b9e
Author: Milan Crha <mcrha redhat com>
Date:   Thu Oct 7 14:02:44 2021 +0200

    I#1653 - Correct Edit as New Message inside a Search Folder
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1653

 src/mail/e-mail-reader-utils.c               |  8 +++---
 src/mail/em-composer-utils.c                 | 38 +++++++++++++++++++++++-----
 src/mail/em-composer-utils.h                 |  3 ++-
 src/modules/mail/e-mail-attachment-handler.c |  2 +-
 src/plugins/templates/templates.c            |  2 +-
 5 files changed, 40 insertions(+), 13 deletions(-)
---
diff --git a/src/mail/e-mail-reader-utils.c b/src/mail/e-mail-reader-utils.c
index 7af1c7a4ee..9746d2d8eb 100644
--- a/src/mail/e-mail-reader-utils.c
+++ b/src/mail/e-mail-reader-utils.c
@@ -1932,6 +1932,7 @@ typedef struct _CreateComposerData {
        CamelMimeMessage *message;
        const gchar *message_uid; /* Allocated on the string pool, use camel_pstring_strdup/free */
        gboolean keep_signature;
+       gboolean replace;
 
        EMailPartList *part_list;
        EMailReplyType reply_type;
@@ -1996,7 +1997,7 @@ mail_reader_edit_messages_composer_created_cb (GObject *source_object,
 
                em_utils_edit_message (
                        composer, ccd->folder, ccd->message, ccd->message_uid,
-                       ccd->keep_signature);
+                       ccd->keep_signature, ccd->replace);
 
                e_mail_reader_composer_created (
                        ccd->reader, composer, ccd->message);
@@ -2062,10 +2063,9 @@ mail_reader_edit_messages_cb (GObject *source_object,
                ccd->reader = g_object_ref (async_context->reader);
                ccd->folder = g_object_ref (folder);
                ccd->message = g_object_ref (CAMEL_MIME_MESSAGE (value));
+               ccd->message_uid = camel_pstring_strdup ((const gchar *) key);
                ccd->keep_signature = async_context->keep_signature;
-
-               if (async_context->replace)
-                       ccd->message_uid = camel_pstring_strdup ((const gchar *) key);
+               ccd->replace = async_context->replace;
 
                e_msg_composer_new (shell, mail_reader_edit_messages_composer_created_cb, ccd);
        }
diff --git a/src/mail/em-composer-utils.c b/src/mail/em-composer-utils.c
index 94ec241b7d..1f9a7ee41a 100644
--- a/src/mail/em-composer-utils.c
+++ b/src/mail/em-composer-utils.c
@@ -2169,6 +2169,8 @@ outbox_data_free (gpointer ptr)
  * @folder: a #CamelFolder
  * @message: a #CamelMimeMessage
  * @message_uid: UID of @message, or %NULL
+ * @keep_signature: whether to keep signature in the original message
+ * @replace_original_message: whether can replace the message in the original Draft/Outbox folder
  *
  * Sets up the @composer with the headers/mime-parts/etc of the @message.
  *
@@ -2179,21 +2181,37 @@ em_utils_edit_message (EMsgComposer *composer,
                        CamelFolder *folder,
                        CamelMimeMessage *message,
                        const gchar *message_uid,
-                       gboolean keep_signature)
+                       gboolean keep_signature,
+                      gboolean replace_original_message)
 {
        ESourceRegistry *registry;
        ESource *source;
+       CamelFolder *real_folder = NULL, *original_folder = NULL;
        gboolean folder_is_sent;
        gboolean folder_is_drafts;
        gboolean folder_is_outbox;
        gboolean folder_is_templates;
+       gchar *real_message_uid = NULL;
        gchar *override_identity_uid = NULL, *override_alias_name = NULL, *override_alias_address = NULL;
 
        g_return_if_fail (E_IS_MSG_COMPOSER (composer));
        g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
-       if (folder)
+       if (folder) {
                g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
+               if (CAMEL_IS_VEE_FOLDER (folder) && message_uid) {
+                       em_utils_get_real_folder_and_message_uid (folder, message_uid, &real_folder, NULL, 
&real_message_uid);
+
+                       if (real_folder) {
+                               original_folder = folder;
+                               folder = real_folder;
+                       }
+
+                       if (real_message_uid)
+                               message_uid = real_message_uid;
+               }
+       }
+
        registry = e_shell_get_registry (e_msg_composer_get_shell (composer));
 
        if (folder) {
@@ -2222,7 +2240,12 @@ em_utils_edit_message (EMsgComposer *composer,
                        }
                }
 
-               source = em_utils_check_send_account_override (e_msg_composer_get_shell (composer), message, 
folder, &override_alias_name, &override_alias_address);
+               source = NULL;
+
+               if (original_folder)
+                       source = em_utils_check_send_account_override (e_msg_composer_get_shell (composer), 
message, original_folder, &override_alias_name, &override_alias_address);
+               if (!source)
+                       source = em_utils_check_send_account_override (e_msg_composer_get_shell (composer), 
message, folder, &override_alias_name, &override_alias_address);
                if (source) {
                        g_free (override_identity_uid);
                        override_identity_uid = e_source_dup_uid (source);
@@ -2278,7 +2301,7 @@ em_utils_edit_message (EMsgComposer *composer,
        e_msg_composer_remove_header (
                composer, "X-Evolution-Replace-Outbox-UID");
 
-       if (message_uid != NULL && folder_is_drafts && folder) {
+       if (message_uid != NULL && folder_is_drafts && folder && replace_original_message) {
                gchar *folder_uri;
 
                folder_uri = e_mail_folder_uri_from_folder (folder);
@@ -2288,7 +2311,7 @@ em_utils_edit_message (EMsgComposer *composer,
 
                g_free (folder_uri);
 
-       } else if (message_uid != NULL && folder_is_outbox) {
+       } else if (message_uid != NULL && folder_is_outbox && replace_original_message) {
                CamelMessageInfo *info;
 
                e_msg_composer_set_header (
@@ -2313,6 +2336,9 @@ em_utils_edit_message (EMsgComposer *composer,
        composer_set_no_change (composer);
 
        gtk_widget_show (GTK_WIDGET (composer));
+
+       g_clear_object (&real_folder);
+       g_free (real_message_uid);
 }
 
 static void
@@ -3788,7 +3814,7 @@ alt_reply_composer_created_cb (GObject *source_object,
                                e_content_editor_set_html_mode (cnt_editor, (context->flags & 
E_MAIL_REPLY_FLAG_FORMAT_HTML) != 0);
                        }
 
-                       em_utils_edit_message (composer, context->folder, context->new_message, 
context->message_uid, TRUE);
+                       em_utils_edit_message (composer, context->folder, context->new_message, 
context->message_uid, TRUE, FALSE);
 
                        if (context->type == E_MAIL_REPLY_TO_SENDER) {
                                /* Reply to sender */
diff --git a/src/mail/em-composer-utils.h b/src/mail/em-composer-utils.h
index f00887e96a..1c30bfc531 100644
--- a/src/mail/em-composer-utils.h
+++ b/src/mail/em-composer-utils.h
@@ -52,7 +52,8 @@ void          em_utils_edit_message           (EMsgComposer *composer,
                                                 CamelFolder *folder,
                                                 CamelMimeMessage *message,
                                                 const gchar *message_uid,
-                                                gboolean keep_signature);
+                                                gboolean keep_signature,
+                                                gboolean replace_original_message);
 void           em_utils_forward_message        (EMsgComposer *composer,
                                                 CamelMimeMessage *message,
                                                 EMailForwardStyle style,
diff --git a/src/modules/mail/e-mail-attachment-handler.c b/src/modules/mail/e-mail-attachment-handler.c
index 69a050ce54..1c99b439db 100644
--- a/src/modules/mail/e-mail-attachment-handler.c
+++ b/src/modules/mail/e-mail-attachment-handler.c
@@ -218,7 +218,7 @@ mail_attachment_handler_composer_created_cb (GObject *source_object,
                } else if (ccd->is_forward) {
                        em_utils_forward_message (composer, ccd->message, ccd->forward_style, ccd->folder, 
NULL);
                } else {
-                       em_utils_edit_message (composer, ccd->folder, ccd->message, NULL, TRUE);
+                       em_utils_edit_message (composer, ccd->folder, ccd->message, NULL, TRUE, FALSE);
                }
        }
 
diff --git a/src/plugins/templates/templates.c b/src/plugins/templates/templates.c
index 7b93fa7ee4..5f2082acd2 100644
--- a/src/plugins/templates/templates.c
+++ b/src/plugins/templates/templates.c
@@ -594,7 +594,7 @@ create_new_message_composer_created_cb (GObject *source_object,
        g_return_if_fail (E_IS_MSG_COMPOSER (composer));
 
        /* Create the composer */
-       em_utils_edit_message (composer, context->template_folder, context->new_message, 
context->source_message_uid, TRUE);
+       em_utils_edit_message (composer, context->template_folder, context->new_message, 
context->source_message_uid, TRUE, FALSE);
 
        em_composer_utils_update_security (composer, context->validity_pgp_sum, context->validity_smime_sum);
 


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