[evolution/gnome-3-18] Bug 754693 - Set "References" header in forwarded messages



commit 07974356d2844a96a88b3c30db6742d85496f3ef
Author: Milan Crha <mcrha redhat com>
Date:   Mon Sep 21 17:11:55 2015 +0200

    Bug 754693 - Set "References" header in forwarded messages

 composer/e-msg-composer.c |   40 ++++++++++++++++++++++++
 composer/e-msg-composer.h |    3 ++
 mail/em-composer-utils.c  |   74 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+), 0 deletions(-)
---
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 82cc284..0f3a48d 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -4822,6 +4822,46 @@ e_msg_composer_remove_header (EMsgComposer *composer,
 }
 
 /**
+ * e_msg_composer_get_header:
+ * @composer: an #EMsgComposer
+ * @name: the header's name
+ * @index: index of the header, 0-based
+ *
+ * Returns header value of the header named @name previously added
+ * by e_msg_composer_add_header() or set by e_msg_composer_set_header().
+ * The @index is which header index to return. Returns %NULL on error
+ * or when the given index of the header couldn't be found.
+ *
+ * Returns: stored header value or NULL, if couldn't be found.
+ *
+ * Since: 3.18.1
+ **/
+const gchar *
+e_msg_composer_get_header (EMsgComposer *composer,
+                          const gchar *name,
+                          gint index)
+{
+       EMsgComposerPrivate *priv;
+       guint ii;
+
+       g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL);
+       g_return_val_if_fail (name != NULL, NULL);
+
+       priv = composer->priv;
+
+       for (ii = 0; ii < priv->extra_hdr_names->len; ii++) {
+               if (g_strcmp0 (priv->extra_hdr_names->pdata[ii], name) == 0) {
+                       if (index <= 0)
+                               return priv->extra_hdr_values->pdata[ii];
+
+                       index--;
+               }
+       }
+
+       return NULL;
+}
+
+/**
  * e_msg_composer_set_draft_headers:
  * @composer: an #EMsgComposer
  * @folder_uri: folder URI of the last saved draft
diff --git a/composer/e-msg-composer.h b/composer/e-msg-composer.h
index 42512b9..cf055d6 100644
--- a/composer/e-msg-composer.h
+++ b/composer/e-msg-composer.h
@@ -117,6 +117,9 @@ void                e_msg_composer_add_header       (EMsgComposer *composer,
 void           e_msg_composer_set_header       (EMsgComposer *composer,
                                                 const gchar *name,
                                                 const gchar *value);
+const gchar *  e_msg_composer_get_header       (EMsgComposer *composer,
+                                                const gchar *name,
+                                                gint index);
 void           e_msg_composer_remove_header    (EMsgComposer *composer,
                                                 const gchar *name);
 void           e_msg_composer_set_draft_headers
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 91b410e..71289c4 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -1883,6 +1883,46 @@ em_utils_get_real_folder_uri_and_message_uid (CamelFolder *folder,
 }
 
 static void
+emu_add_composer_references_from_message (EMsgComposer *composer,
+                                         CamelMimeMessage *message)
+{
+       const gchar *message_id_header;
+
+       g_return_if_fail (E_IS_MSG_COMPOSER (composer));
+       g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
+
+       message_id_header = camel_mime_message_get_message_id (message);
+       if (message_id_header && *message_id_header) {
+               GString *references = g_string_new ("");
+               gint ii = 0;
+               const gchar *value;
+
+               while (value = e_msg_composer_get_header (composer, "References", ii), value) {
+                       ii++;
+
+                       if (references->len)
+                               g_string_append_c (references, ' ');
+                       g_string_append (references, value);
+               }
+
+               if (references->len)
+                       g_string_append_c (references, ' ');
+
+               if (*message_id_header != '<')
+                       g_string_append_c (references, '<');
+
+               g_string_append (references, message_id_header);
+
+               if (*message_id_header != '<')
+                       g_string_append_c (references, '>');
+
+               e_msg_composer_set_header (composer, "References", references->str);
+
+               g_string_free (references, TRUE);
+       }
+}
+
+static void
 real_update_forwarded_flag (gpointer uid,
                             gpointer folder)
 {
@@ -1972,6 +2012,8 @@ forward_non_attached (EMailBackend *backend,
 
                e_msg_composer_set_body_text (composer, text, TRUE);
 
+               emu_add_composer_references_from_message (composer, message);
+
                if (uid != NULL) {
                        gchar *folder_uri = NULL, *tmp_message_uid = NULL;
 
@@ -2068,6 +2110,7 @@ em_utils_forward_attachment (EMailBackend *backend,
                              GPtrArray *uids)
 {
        EShell *shell;
+       CamelDataWrapper *content;
        EMsgComposer *composer;
 
        g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
@@ -2082,6 +2125,37 @@ em_utils_forward_attachment (EMailBackend *backend,
 
        e_msg_composer_attach (composer, part);
 
+       content = camel_medium_get_content (CAMEL_MEDIUM (part));
+       if (CAMEL_IS_MIME_MESSAGE (content)) {
+               emu_add_composer_references_from_message (composer, CAMEL_MIME_MESSAGE (content));
+       } else if (CAMEL_IS_MULTIPART (content)) {
+               const gchar *mime_type;
+
+               mime_type = camel_data_wrapper_get_mime_type (content);
+               if (mime_type && g_ascii_strcasecmp (mime_type, "multipart/digest") == 0) {
+                       /* This is the way evolution forwards multiple messages as attachment */
+                       CamelMultipart *multipart;
+                       guint ii, nparts;
+
+                       multipart = CAMEL_MULTIPART (content);
+                       nparts = camel_multipart_get_number (multipart);
+
+                       for (ii = 0; ii < nparts; ii++) {
+                               CamelMimePart *mpart;
+
+                               mpart = camel_multipart_get_part (multipart, ii);
+                               mime_type = camel_data_wrapper_get_mime_type (CAMEL_DATA_WRAPPER (mpart));
+
+                               if (mime_type && g_ascii_strcasecmp (mime_type, "message/rfc822") == 0) {
+                                       content = camel_medium_get_content (CAMEL_MEDIUM (mpart));
+
+                                       if (CAMEL_IS_MIME_MESSAGE (content))
+                                               emu_add_composer_references_from_message (composer, 
CAMEL_MIME_MESSAGE (content));
+                               }
+                       }
+               }
+       }
+
        if (uids != NULL)
                setup_forward_attached_callbacks (composer, folder, uids);
 


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