[evolution] Bug 769396 - Quoted Reply with Template



commit 49aa88030a7e0f1ec8e8ddd42bbb7b6b2ce20eb4
Author: Milan Crha <mcrha redhat com>
Date:   Fri Nov 9 10:34:10 2018 +0100

    Bug 769396 - Quoted Reply with Template
    
    Closes https://bugzilla.gnome.org/show_bug.cgi?id=769396

 src/mail/e-mail-templates.c                        | 128 +++++++++++++++++-
 src/mail/e-mail-templates.h                        |   4 +
 src/mail/em-composer-utils.c                       | 147 ++++++++++++---------
 src/mail/em-composer-utils.h                       |  10 ++
 src/modules/webkit-editor/e-webkit-editor.c        |   3 +-
 .../templates/org-gnome-templates.eplug.xml        |   2 +-
 src/plugins/templates/templates.c                  |   6 +-
 7 files changed, 230 insertions(+), 70 deletions(-)
---
diff --git a/src/mail/e-mail-templates.c b/src/mail/e-mail-templates.c
index 8d3bb7a5bb..f005e87fad 100644
--- a/src/mail/e-mail-templates.c
+++ b/src/mail/e-mail-templates.c
@@ -26,6 +26,9 @@
 
 #include "e-util/e-util.h"
 
+#include "em-composer-utils.h"
+#include "em-utils.h"
+
 #include "e-mail-templates.h"
 
 /* Replaces $ORIG[variable] in given template by given replacement from the original message */
@@ -91,8 +94,27 @@ replace_email_addresses (GString *template,
        g_string_free (emails, TRUE);
 }
 
+static ESource *
+ref_identity_source_from_message_and_folder (CamelMimeMessage *message,
+                                            CamelFolder *folder,
+                                            const gchar *message_uid)
+{
+       EShell *shell;
+
+       g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL);
+
+       shell = e_shell_get_default ();
+       if (!shell)
+               return NULL;
+
+       return em_composer_utils_guess_identity_source (shell, message, folder, message_uid, NULL, NULL);
+}
+
 static CamelMimePart *
 fill_template (CamelMimeMessage *message,
+              CamelFolder *source_folder,
+              const gchar *source_message_uid,
+              CamelFolder *templates_folder,
                CamelMimePart *template)
 {
        const CamelNameValueArray *headers;
@@ -107,6 +129,7 @@ fill_template (CamelMimeMessage *message,
        gint i;
        guint jj, len;
        gboolean message_html, template_html;
+       gboolean has_quoted_body;
 
        ct = camel_mime_part_get_content_type (template);
        template_html = ct && camel_content_type_is (ct, "text", "html");
@@ -179,8 +202,27 @@ fill_template (CamelMimeMessage *message,
        internet_address = camel_mime_message_get_from (message);
        replace_email_addresses (template_body, internet_address, "from");
 
+       has_quoted_body = e_util_strstrcase (template_body->str, "$ORIG[quoted-body]") != NULL;
+       if (has_quoted_body && !template_html) {
+               gchar *html;
+
+               template_html = TRUE;
+
+               html = camel_text_to_html (
+                       template_body->str,
+                       CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
+                       CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
+                       CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
+                       CAMEL_MIME_FILTER_TOHTML_MARK_CITATION |
+                       CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0);
+               g_string_assign (template_body, html);
+               g_free (html);
+
+               g_string_append (template_body, "<!-- disable-format-prompt -->");
+       }
+
        /* Now extract body of the original message and replace the $ORIG[body] modifier in template */
-       if (message_part && e_util_strstrcase (template_body->str, "$ORIG[body]")) {
+       if (message_part && (has_quoted_body || e_util_strstrcase (template_body->str, "$ORIG[body]"))) {
                GString *message_body;
                CamelStream *mem_stream;
 
@@ -220,17 +262,77 @@ fill_template (CamelMimeMessage *message,
                                CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
                                CAMEL_MIME_FILTER_TOHTML_MARK_CITATION |
                                CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0);
-                       g_string_assign (message_body, html);
+                       replace_template_variable (template_body, "body", html);
                        g_free (html);
                } else if (!template_html && message_html) {
+                       gchar *html;
+
                        g_string_prepend (message_body, "<pre>");
                        g_string_append (message_body, "</pre>");
-               } /* Other cases should not occur. And even if they happen to do, there's nothing we can 
really do about it */
 
-               replace_template_variable (template_body, "body", message_body->str);
+                       template_html = TRUE;
+
+                       html = camel_text_to_html (
+                               template_body->str,
+                               CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
+                               CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
+                               CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
+                               CAMEL_MIME_FILTER_TOHTML_MARK_CITATION |
+                               CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0);
+                       g_string_assign (template_body, html);
+                       g_free (html);
+
+                       replace_template_variable (template_body, "body", message_body->str);
+               } else { /* Other cases should not occur. And even if they happen to do, there's nothing we 
can really do about it */
+                       replace_template_variable (template_body, "body", message_body->str);
+               }
+
+               if (has_quoted_body) {
+                       if (!message_html) {
+                               gchar *html = camel_text_to_html (
+                                       message_body->str,
+                                       CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
+                                       CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
+                                       CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
+                                       CAMEL_MIME_FILTER_TOHTML_QUOTE_CITATION |
+                                       CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0);
+                               g_string_assign (message_body, html);
+                               g_free (html);
+                       }
+
+                       g_string_prepend (message_body, "<blockquote type=\"cite\">");
+                       g_string_append (message_body, "</blockquote>");
+
+                       replace_template_variable (template_body, "quoted-body", message_body->str);
+               }
+
                g_string_free (message_body, TRUE);
        } else {
                replace_template_variable (template_body, "body", "");
+               replace_template_variable (template_body, "quoted-body", "");
+       }
+
+       if (e_util_strstrcase (template_body->str, "$ORIG[reply-credits]")) {
+               ESource *identity_source;
+               gchar *reply_credits;
+
+               identity_source = ref_identity_source_from_message_and_folder (message, source_folder, 
source_message_uid);
+
+               reply_credits = em_composer_utils_get_reply_credits (identity_source, message);
+
+               if (reply_credits && template_html) {
+                       gchar *html = camel_text_to_html (
+                               reply_credits,
+                               CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
+                               CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0);
+                       g_free (reply_credits);
+                       reply_credits = html;
+               }
+
+               replace_template_variable (template_body, "reply-credits", reply_credits ? reply_credits : 
"");
+
+               g_clear_object (&identity_source);
+               g_free (reply_credits);
        }
 
        return_part = camel_mime_part_new ();
@@ -284,6 +386,8 @@ find_template_part_in_multipart (CamelMultipart *multipart,
 
 CamelMimeMessage *
 e_mail_templates_apply_sync (CamelMimeMessage *source_message,
+                            CamelFolder *source_folder,
+                            const gchar *source_message_uid,
                             CamelFolder *templates_folder,
                             const gchar *templates_message_uid,
                             GCancellable *cancellable,
@@ -333,7 +437,7 @@ e_mail_templates_apply_sync (CamelMimeMessage *source_message,
 
                /* Here replace all the modifiers in template body by values
                   from message and return the newly created part */
-               out_part = fill_template (source_message, template_part);
+               out_part = fill_template (source_message, source_folder, source_message_uid, 
templates_folder, template_part);
 
                /* Assigning part directly to mime_message causes problem with
                   "Content-type" header displaying in the HTML message (camel parsing bug?) */
@@ -408,7 +512,9 @@ e_mail_templates_apply_sync (CamelMimeMessage *source_message,
 
 typedef struct _AsyncContext {
        CamelMimeMessage *source_message;
+       CamelFolder *source_folder;
        CamelFolder *templates_folder;
+       gchar *source_message_uid;
        gchar *templates_message_uid;
        CamelMimeMessage *result_message;
 } AsyncContext;
@@ -420,8 +526,10 @@ async_context_free (gpointer ptr)
 
        if (context) {
                g_clear_object (&context->source_message);
+               g_clear_object (&context->source_folder);
                g_clear_object (&context->templates_folder);
                g_clear_object (&context->result_message);
+               g_free (context->source_message_uid);
                g_free (context->templates_message_uid);
                g_free (context);
        }
@@ -438,8 +546,10 @@ e_mail_templates_apply_thread (ESimpleAsyncResult *simple,
        context = e_simple_async_result_get_op_pointer (simple);
        g_return_if_fail (context != NULL);
 
-       context->result_message = e_mail_templates_apply_sync (context->source_message,
-               context->templates_folder, context->templates_message_uid, cancellable, &local_error);
+       context->result_message = e_mail_templates_apply_sync (
+               context->source_message, context->source_folder, context->source_message_uid,
+               context->templates_folder, context->templates_message_uid,
+               cancellable, &local_error);
 
        if (local_error)
                e_simple_async_result_take_error (simple, local_error);
@@ -447,6 +557,8 @@ e_mail_templates_apply_thread (ESimpleAsyncResult *simple,
 
 void
 e_mail_templates_apply (CamelMimeMessage *source_message,
+                       CamelFolder *source_folder,
+                       const gchar *source_message_uid,
                        CamelFolder *templates_folder,
                        const gchar *templates_message_uid,
                        GCancellable *cancellable,
@@ -463,6 +575,8 @@ e_mail_templates_apply (CamelMimeMessage *source_message,
 
        context = g_new0 (AsyncContext, 1);
        context->source_message = g_object_ref (source_message);
+       context->source_folder = source_folder ? g_object_ref (source_folder) : NULL;
+       context->source_message_uid = g_strdup (source_message_uid);
        context->templates_folder = g_object_ref (templates_folder);
        context->templates_message_uid = g_strdup (templates_message_uid);
        context->result_message = NULL;
diff --git a/src/mail/e-mail-templates.h b/src/mail/e-mail-templates.h
index 348fb112c2..004e051628 100644
--- a/src/mail/e-mail-templates.h
+++ b/src/mail/e-mail-templates.h
@@ -29,11 +29,15 @@ G_BEGIN_DECLS
 
 CamelMimeMessage *
                e_mail_templates_apply_sync     (CamelMimeMessage *source_message,
+                                                CamelFolder *source_folder,
+                                                const gchar *source_message_uid,
                                                 CamelFolder *templates_folder,
                                                 const gchar *templates_message_uid,
                                                 GCancellable *cancellable,
                                                 GError **error);
 void           e_mail_templates_apply          (CamelMimeMessage *source_message,
+                                                CamelFolder *source_folder,
+                                                const gchar *source_message_uid,
                                                 CamelFolder *templates_folder,
                                                 const gchar *templates_message_uid,
                                                 GCancellable *cancellable,
diff --git a/src/mail/em-composer-utils.c b/src/mail/em-composer-utils.c
index 5dadc5f5ad..76f6e9bdd6 100644
--- a/src/mail/em-composer-utils.c
+++ b/src/mail/em-composer-utils.c
@@ -1438,6 +1438,44 @@ sort_sources_by_ui (GList **psources,
        g_hash_table_destroy (uids_order);
 }
 
+/* (trasfer full) */
+ESource *
+em_composer_utils_guess_identity_source (EShell *shell,
+                                        CamelMimeMessage *message,
+                                        CamelFolder *folder,
+                                        const gchar *message_uid,
+                                        gchar **out_identity_name,
+                                        gchar **out_identity_address)
+{
+       ESource *source;
+
+       g_return_val_if_fail (E_IS_SHELL (shell), NULL);
+
+       /* Check send account override for the passed-in folder */
+       source = em_utils_check_send_account_override (shell, message, folder, out_identity_name, 
out_identity_address);
+
+       /* If not set and it's a search folder, then check the original folder */
+       if (!source && message_uid && CAMEL_IS_VEE_FOLDER (folder)) {
+               CamelMessageInfo *mi = camel_folder_get_message_info (folder, message_uid);
+               if (mi) {
+                       CamelFolder *location;
+
+                       location = camel_vee_folder_get_location (CAMEL_VEE_FOLDER (folder), 
(CamelVeeMessageInfo *) mi, NULL);
+                       if (location)
+                               source = em_utils_check_send_account_override (shell, message, location, 
out_identity_name, out_identity_address);
+                       g_clear_object (&mi);
+               }
+       }
+
+       /* If no send account override, then guess */
+       if (!source) {
+               source = em_utils_guess_mail_identity_with_recipients_and_sort (e_shell_get_registry (shell),
+                       message, folder, message_uid, out_identity_name, out_identity_address, 
sort_sources_by_ui, shell);
+       }
+
+       return source;
+}
+
 /* Composing messages... */
 
 static CamelMimeMessage *em_utils_get_composer_recipients_as_message (EMsgComposer *composer);
@@ -1475,27 +1513,7 @@ set_up_new_composer (EMsgComposer *composer,
 
                        shell = e_msg_composer_get_shell (composer);
 
-                       /* Check send account override for the passed-in folder */
-                       source = em_utils_check_send_account_override (shell, message, folder, 
&identity_name, &identity_address);
-
-                       /* If not set and it's a search folder, then check the original folder */
-                       if (!source && message_uid && CAMEL_IS_VEE_FOLDER (folder)) {
-                               CamelMessageInfo *mi = camel_folder_get_message_info (folder, message_uid);
-                               if (mi) {
-                                       CamelFolder *location;
-
-                                       location = camel_vee_folder_get_location (CAMEL_VEE_FOLDER (folder), 
(CamelVeeMessageInfo *) mi, NULL);
-                                       if (location)
-                                               source = em_utils_check_send_account_override (shell, 
message, location, &identity_name, &identity_address);
-                                       g_clear_object (&mi);
-                               }
-                       }
-
-                       /* If no send account override, then guess */
-                       if (!source) {
-                               source = em_utils_guess_mail_identity_with_recipients_and_sort (
-                                       registry, message, folder, message_uid, &identity_name, 
&identity_address, sort_sources_by_ui, shell);
-                       }
+                       source = em_composer_utils_guess_identity_source (shell, message, folder, 
message_uid, &identity_name, &identity_address);
                }
 
                /* In case of search folder, try to guess the store from
@@ -2008,6 +2026,25 @@ traverse_parts (GSList *clues,
        }
 }
 
+static ESource *
+emcu_ref_identity_source_from_composer (EMsgComposer *composer)
+{
+       EComposerHeaderTable *table;
+       ESource *source = NULL;
+       gchar *identity_uid;
+
+       if (!composer)
+               return NULL;
+
+       table = e_msg_composer_get_header_table (composer);
+       identity_uid = e_composer_header_table_dup_identity_uid (table, NULL, NULL);
+       if (identity_uid)
+               source = e_composer_header_table_ref_source (table, identity_uid);
+       g_free (identity_uid);
+
+       return source;
+}
+
 static void
 emcu_change_locale (const gchar *lc_messages,
                    const gchar *lc_time,
@@ -2052,35 +2089,22 @@ emcu_change_locale (const gchar *lc_messages,
 }
 
 static void
-emcu_prepare_attribution_locale (EMsgComposer *composer,
+emcu_prepare_attribution_locale (ESource *identity_source,
                                 gchar **out_lc_messages,
                                 gchar **out_lc_time)
 {
-       EComposerHeaderTable *table;
-       ESource *source = NULL;
-       gchar *uid, *lang = NULL;
+       gchar *lang = NULL;
 
        g_return_if_fail (out_lc_messages != NULL);
        g_return_if_fail (out_lc_time != NULL);
 
-       if (!composer)
-               return;
-
-       table = e_msg_composer_get_header_table (composer);
-       uid = e_composer_header_table_dup_identity_uid (table, NULL, NULL);
-       if (uid)
-               source = e_composer_header_table_ref_source (table, uid);
-       g_free (uid);
-
-       if (source && e_source_has_extension (source, E_SOURCE_EXTENSION_MAIL_COMPOSITION)) {
+       if (identity_source && e_source_has_extension (identity_source, E_SOURCE_EXTENSION_MAIL_COMPOSITION)) 
{
                ESourceMailComposition *extension;
 
-               extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MAIL_COMPOSITION);
+               extension = e_source_get_extension (identity_source, E_SOURCE_EXTENSION_MAIL_COMPOSITION);
                lang = e_source_mail_composition_dup_language (extension);
        }
 
-       g_clear_object (&source);
-
        if (!lang || !*lang) {
                GSettings *settings;
 
@@ -2181,8 +2205,15 @@ quoting_text (QuotingTextEnum type,
 
        g_free (text);
 
-       if (composer)
-               emcu_prepare_attribution_locale (composer, &restore_lc_messages, &restore_lc_time);
+       if (composer) {
+               ESource *identity_source;
+
+               identity_source = emcu_ref_identity_source_from_composer (composer);
+
+               emcu_prepare_attribution_locale (identity_source, &restore_lc_messages, &restore_lc_time);
+
+               g_clear_object (&identity_source);
+       }
 
        text = g_strdup (_(conf_messages[type].message));
 
@@ -2792,7 +2823,6 @@ void
 em_utils_redirect_message (EMsgComposer *composer,
                            CamelMimeMessage *message)
 {
-       ESourceRegistry *registry;
        ESource *source;
        EShell *shell;
        CamelMedium *medium;
@@ -2816,13 +2846,7 @@ em_utils_redirect_message (EMsgComposer *composer,
        while (camel_medium_get_header (medium, "Resent-Bcc"))
                camel_medium_remove_header (medium, "Resent-Bcc");
 
-       registry = e_shell_get_registry (shell);
-
-       /* This returns a new ESource reference. */
-       source = em_utils_check_send_account_override (shell, message, NULL, &alias_name, &alias_address);
-       if (!source)
-               source = em_utils_guess_mail_identity_with_recipients_and_sort (
-                       registry, message, NULL, NULL, &alias_name, &alias_address, sort_sources_by_ui, 
shell);
+       source = em_composer_utils_guess_identity_source (shell, message, NULL, NULL, &alias_name, 
&alias_address);
 
        if (source != NULL) {
                identity_uid = e_source_dup_uid (source);
@@ -3548,9 +3572,9 @@ static struct {
        { "{TimeZone}", ATTRIB_TIMEZONE, { "%+05d", NULL } }
 };
 
-static gchar *
-attribution_format (EMsgComposer *composer,
-                   CamelMimeMessage *message)
+gchar *
+em_composer_utils_get_reply_credits (ESource *identity_source,
+                                    CamelMimeMessage *message)
 {
        register const gchar *inptr;
        const gchar *start;
@@ -3562,7 +3586,7 @@ attribution_format (EMsgComposer *composer,
        gint type;
        gchar *format, *restore_lc_messages = NULL, *restore_lc_time = NULL;
 
-       emcu_prepare_attribution_locale (composer, &restore_lc_messages, &restore_lc_time);
+       emcu_prepare_attribution_locale (identity_source, &restore_lc_messages, &restore_lc_time);
 
        format = quoting_text (QUOTING_ATTRIBUTION, NULL);
        str = g_string_new ("");
@@ -3715,6 +3739,7 @@ composer_set_body (EMsgComposer *composer,
                    EMailPartList *parts_list)
 {
        gchar *text, *credits, *original;
+       ESource *identity_source;
        CamelMimePart *part;
        CamelSession *session;
        GSettings *settings;
@@ -3750,8 +3775,13 @@ composer_set_body (EMsgComposer *composer,
 
        case E_MAIL_REPLY_STYLE_QUOTED:
        default:
+               identity_source = emcu_ref_identity_source_from_composer (composer);
+
                /* do what any sane user would want when replying... */
-               credits = attribution_format (composer, message);
+               credits = em_composer_utils_get_reply_credits (identity_source, message);
+
+               g_clear_object (&identity_source);
+
                text = em_utils_message_to_html (
                        session, message, credits, E_MAIL_FORMATTER_QUOTE_FLAG_CITE | keep_sig_flag,
                        parts_list, NULL, NULL, &validity_found);
@@ -4496,7 +4526,7 @@ em_utils_reply_alternative (GtkWindow *parent,
                context->template_preserve_subject = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON 
(preserve_message_subject));
 
                if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (apply_template))) {
-                       e_mail_templates_apply (context->source_message, template_folder, 
template_message_uid,
+                       e_mail_templates_apply (context->source_message, context->folder, message_uid, 
template_folder, template_message_uid,
                                NULL, alt_reply_template_applied_cb, context);
 
                } else {
@@ -4570,11 +4600,8 @@ em_utils_reply_to_message (EMsgComposer *composer,
        shell = e_msg_composer_get_shell (composer);
        registry = e_shell_get_registry (shell);
 
-       /* This returns a new ESource reference. */
-       source = em_utils_check_send_account_override (shell, message, folder, &identity_name, 
&identity_address);
-       if (!source)
-               source = em_utils_guess_mail_identity_with_recipients_and_sort (
-                       registry, message, folder, message_uid, &identity_name, &identity_address, 
sort_sources_by_ui, shell);
+       source = em_composer_utils_guess_identity_source (shell, message, folder, message_uid, 
&identity_name, &identity_address);
+
        if (source != NULL) {
                identity_uid = e_source_dup_uid (source);
                if (!(reply_flags & E_MAIL_REPLY_FLAG_FORCE_STYLE) &&
@@ -4644,7 +4671,7 @@ em_utils_reply_to_message (EMsgComposer *composer,
                used_identity_uid = e_composer_header_table_dup_identity_uid (header_table, NULL, NULL);
 
                if (used_identity_uid) {
-                       source = e_source_registry_ref_source (e_shell_get_registry (shell), 
used_identity_uid);
+                       source = e_source_registry_ref_source (registry, used_identity_uid);
                        if (source) {
                                if (!(reply_flags & E_MAIL_REPLY_FLAG_FORCE_STYLE) &&
                                    e_source_has_extension (source, E_SOURCE_EXTENSION_MAIL_COMPOSITION)) {
diff --git a/src/mail/em-composer-utils.h b/src/mail/em-composer-utils.h
index 4f7e7f4b43..252660fb59 100644
--- a/src/mail/em-composer-utils.h
+++ b/src/mail/em-composer-utils.h
@@ -113,7 +113,17 @@ gchar *            em_composer_utils_get_forward_marker
                                                (EMsgComposer *composer);
 gchar *                em_composer_utils_get_original_marker
                                                (EMsgComposer *composer);
+gchar *                em_composer_utils_get_reply_credits
+                                               (ESource *identity_source,
+                                                CamelMimeMessage *message);
 void           em_utils_add_installed_languages(GtkComboBoxText *combo);
+ESource *      em_composer_utils_guess_identity_source
+                                               (EShell *shell,
+                                                CamelMimeMessage *message,
+                                                CamelFolder *folder,
+                                                const gchar *message_uid,
+                                                gchar **out_identity_name,
+                                                gchar **out_identity_address);
 
 G_END_DECLS
 
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 5e46b0f8e9..33af2bd663 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -1862,7 +1862,8 @@ webkit_editor_insert_content (EContentEditor *editor,
 
                /* Only convert messages that are in HTML */
                if (!(wk_editor->priv->html_mode)) {
-                       if (strstr (content, "<!-- text/html -->")) {
+                       if (strstr (content, "<!-- text/html -->") &&
+                           !strstr (content, "<!-- disable-format-prompt -->")) {
                                if (!show_lose_formatting_dialog (wk_editor)) {
                                        set_convert_in_situ (wk_editor, FALSE);
                                        wk_editor->priv->reload_in_progress = TRUE;
diff --git a/src/plugins/templates/org-gnome-templates.eplug.xml 
b/src/plugins/templates/org-gnome-templates.eplug.xml
index 5bfa8a1e2b..737846f62d 100644
--- a/src/plugins/templates/org-gnome-templates.eplug.xml
+++ b/src/plugins/templates/org-gnome-templates.eplug.xml
@@ -7,7 +7,7 @@
         _name="Templates">
         <_description>Drafts based template plugin.
         
-        You can use variables like $ORIG[subject], $ORIG[from], $ORIG[to] or $ORIG[body], which will be 
replaced by values from an email you are replying to.</_description>
+        You can use variables like $ORIG[subject], $ORIG[from], $ORIG[to], $ORIG[body], $ORIG[quoted-body] 
or $ORIG[reply-credits], which will be replaced by values from an email you are replying to.</_description>
         <author name="Bharath Acharya" email="abharath novell com"/>
         <author name="Diego Escalante Urrelo" email="diegoe gnome org"/>
         <author name="Dan Vratil" email="dvratil redhat com"/>
diff --git a/src/plugins/templates/templates.c b/src/plugins/templates/templates.c
index 79789dc5f0..746db14239 100644
--- a/src/plugins/templates/templates.c
+++ b/src/plugins/templates/templates.c
@@ -52,6 +52,7 @@ struct _AsyncContext {
        CamelFolder *template_folder;
        gchar *source_folder_uri;
        gchar *source_message_uid;
+       gchar *orig_source_message_uid;
        gchar *template_message_uid;
 };
 
@@ -129,6 +130,7 @@ async_context_free (AsyncContext *context)
 
        g_free (context->source_folder_uri);
        g_free (context->source_message_uid);
+       g_free (context->orig_source_message_uid);
        g_free (context->template_message_uid);
 
        g_slice_free (AsyncContext, context);
@@ -669,7 +671,8 @@ template_got_source_message (CamelFolder *folder,
 
        context->source_message = message;
 
-       e_mail_templates_apply (context->source_message, context->template_folder, 
context->template_message_uid,
+       e_mail_templates_apply (context->source_message, folder, context->orig_source_message_uid,
+               context->template_folder, context->template_message_uid,
                e_activity_get_cancellable (context->activity), templates_template_applied_cb, context);
 }
 
@@ -702,6 +705,7 @@ action_reply_with_template_cb (EMailTemplatesStore *templates_store,
        context = g_slice_new0 (AsyncContext);
        context->activity = activity;
        context->reader = g_object_ref (reader);
+       context->orig_source_message_uid = g_strdup (message_uid);
        context->template_folder = g_object_ref (template_folder);
        context->template_message_uid = g_strdup (template_message_uid);
 


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