Added support for setting References and In-Reply-To: mime fields
authorJose Dapena Paz <jdapena@igalia.com>
Thu, 26 Mar 2009 17:06:53 +0000 (17:06 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Thu, 26 Mar 2009 17:06:53 +0000 (17:06 +0000)
pmo-trunk-r8432

src/gnome/modest-msg-edit-window.c
src/hildon2/modest-msg-edit-window.c
src/maemo/modest-msg-edit-window.c
src/modest-mail-operation.c
src/modest-mail-operation.h
src/modest-tny-msg.c
src/modest-tny-msg.h
src/modest-ui-actions.c
src/widgets/modest-msg-edit-window.h

index b02ad9f..e9cd50a 100644 (file)
@@ -89,6 +89,9 @@ struct _ModestMsgEditWindowPrivate {
        TnyMsg      *outbox_msg;
        gchar       *msg_uid;
 
+       gchar       *references;
+       gchar       *in_reply_to;
+
        gboolean    sent;
 };
 
@@ -179,6 +182,8 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
        priv->draft_msg = NULL;
        priv->outbox_msg = NULL;
        priv->msg_uid = NULL;
+       priv->references = NULL;
+       priv->in_reply_to = NULL;
 }
 
 /** 
@@ -339,6 +344,8 @@ modest_msg_edit_window_finalize (GObject *obj)
                priv->outbox_msg = NULL;
        }
        g_free (priv->msg_uid);
+       g_free (priv->references);
+       g_free (priv->in_reply_to);
        
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
@@ -405,6 +412,8 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg)
        if (subject)
                gtk_entry_set_text (GTK_ENTRY(priv->subject_field), subject);
 
+       modest_tny_msg_get_references (TNY_MSG (msg), NULL, &(priv->references), &(priv->in_reply_to));
+
        modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), msg);
        priv->attachments = modest_attachments_view_get_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
        update_next_cid (self, priv->attachments);
@@ -599,6 +608,8 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
        data->cc      =  g_strdup ( gtk_entry_get_text (GTK_ENTRY(priv->cc_field)));
        data->bcc     =  g_strdup ( gtk_entry_get_text (GTK_ENTRY(priv->bcc_field)));
        data->subject =  g_strdup ( gtk_entry_get_text (GTK_ENTRY(priv->subject_field)));
+       data->references = g_strdup (priv->references);
+       data->in_reply_to = g_strdup (priv->in_reply_to);
 
 /*     GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body)); */
 /*     GtkTextIter b, e; */
@@ -663,6 +674,8 @@ modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window,
        g_free (data->subject);
        g_free (data->plain_body);
        g_free (data->html_body);
+       g_free (data->references);
+       g_free (data->in_reply_to);
 
        if (data->draft_msg != NULL) {
                g_object_unref (data->draft_msg);
index 544bfcb..03d0aec 100644 (file)
@@ -241,6 +241,9 @@ struct _ModestMsgEditWindowPrivate {
        GtkWidget   *from_field;
        gchar       *last_from_account;
        gchar       *original_account_name;
+
+       gchar       *references;
+       gchar       *in_reply_to;
        
        GtkWidget   *to_field;
        GtkWidget   *cc_field;
@@ -425,6 +428,9 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
        priv->font_dialog = NULL;
        priv->app_menu = NULL;
 
+       priv->references = NULL;
+       priv->in_reply_to = NULL;
+
        if (!is_wp_text_buffer_started) {
                is_wp_text_buffer_started = TRUE;
                wp_text_buffer_library_init ();
@@ -974,6 +980,8 @@ modest_msg_edit_window_finalize (GObject *obj)
                g_free (priv->original_account_name);
        g_free (priv->msg_uid);
        g_free (priv->last_search);
+       g_free (priv->references);
+       g_free (priv->in_reply_to);
        g_object_unref (priv->faces_model);
        g_object_unref (priv->sizes_model);
        g_object_unref (priv->attachments);
@@ -1212,6 +1220,8 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
        cc      = tny_header_dup_cc (header);
        bcc     = tny_header_dup_bcc (header);
        subject = tny_header_dup_subject (header);
+
+       modest_tny_msg_get_references (TNY_MSG (msg), NULL, &(priv->references), &(priv->in_reply_to));
        priority_flags = tny_header_get_priority (header);
 
        if (to)
@@ -1628,6 +1638,8 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
        data->cc      =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->cc_field)));
        data->bcc     =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->bcc_field)));
        data->subject =  g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->subject_field)));
+       data->references = g_strdup (priv->references);
+       data->in_reply_to = g_strdup (priv->in_reply_to);
        if (priv->draft_msg) {
                data->draft_msg = g_object_ref (priv->draft_msg);
        } else if (priv->outbox_msg) {
@@ -1727,6 +1739,8 @@ modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window,
        g_free (data->plain_body);
        g_free (data->html_body);
        g_free (data->account_name);
+       g_free (data->references);
+       g_free (data->in_reply_to);
        
        if (data->draft_msg != NULL) {
                g_object_unref (data->draft_msg);
index c7fa46b..e485047 100644 (file)
@@ -288,6 +288,8 @@ struct _ModestMsgEditWindowPrivate {
        TnyMsg      *draft_msg;
        TnyMsg      *outbox_msg;
        gchar       *msg_uid;
+       gchar       *references;
+       gchar       *in_reply_to;
 
        gboolean    sent;
 };
@@ -425,6 +427,8 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
        priv->draft_msg = NULL;
        priv->outbox_msg = NULL;
        priv->msg_uid = NULL;
+       priv->references = NULL;
+       priv->in_reply_to = NULL;
 
        priv->can_undo = FALSE;
        priv->can_redo = FALSE;
@@ -963,6 +967,8 @@ modest_msg_edit_window_finalize (GObject *obj)
        if (priv->original_account_name)
                g_free (priv->original_account_name);
        g_free (priv->msg_uid);
+       g_free (priv->references);
+       g_free (priv->in_reply_to);
        g_free (priv->last_search);
        g_slist_free (priv->font_items_group);
        g_slist_free (priv->size_items_group);
@@ -1189,6 +1195,7 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
                gtk_entry_set_text (GTK_ENTRY(priv->subject_field), subject);
        modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW(self),
                                                   priority_flags);
+       modest_tny_msg_get_references (TNY_MSG (msg), NULL, &(priv->references), &(priv->in_reply_to));
 
        update_window_title (self);
 
@@ -1623,6 +1630,8 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
        data->cc      =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->cc_field)));
        data->bcc     =  g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->bcc_field)));
        data->subject =  g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->subject_field)));
+       data->references = g_strdup (priv->references);
+       data->in_reply_to = g_strdup (priv->in_reply_to);
        if (priv->draft_msg) {
                data->draft_msg = g_object_ref (priv->draft_msg);
        } else if (priv->outbox_msg) {
@@ -1722,6 +1731,8 @@ modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window,
        g_free (data->plain_body);
        g_free (data->html_body);
        g_free (data->account_name);
+       g_free (data->in_reply_to);
+       g_free (data->references);
        
        if (data->draft_msg != NULL) {
                g_object_unref (data->draft_msg);
index 4ca9397..61eead7 100644 (file)
@@ -231,6 +231,7 @@ static void          modest_mail_operation_create_msg (ModestMailOperation *self
                                                       const gchar *html_body, const GList *attachments_list,
                                                       const GList *images_list,
                                                       TnyHeaderFlags priority_flags,
+                                                      const gchar *references, const gchar *in_reply_to,
                                                       ModestMailOperationCreateMsgCallback callback,
                                                       gpointer userdata);
 
@@ -243,6 +244,8 @@ typedef struct
        gchar *cc;
        gchar *bcc;
        gchar *subject;
+       gchar *references;
+       gchar *in_reply_to;
        gchar *plain_body;
        gchar *html_body;
        GList *attachments_list;
@@ -828,12 +831,16 @@ create_msg_thread (gpointer thread_data)
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mail_op);
        if (info->html_body == NULL) {
                new_msg = modest_tny_msg_new (info->to, info->from, info->cc, 
-                                             info->bcc, info->subject, info->plain_body, 
+                                             info->bcc, info->subject, 
+                                             info->references, info->in_reply_to,
+                                             info->plain_body, 
                                              info->attachments_list, &attached,
                                              &(priv->error));
        } else {
                new_msg = modest_tny_msg_new_html_plain (info->to, info->from, info->cc,
-                                                        info->bcc, info->subject, info->html_body,
+                                                        info->bcc, info->subject, 
+                                                        info->references, info->in_reply_to,
+                                                        info->html_body,
                                                         info->plain_body, info->attachments_list,
                                                         info->images_list, &attached,
                                                         &(priv->error));
@@ -867,6 +874,8 @@ create_msg_thread (gpointer thread_data)
        g_free (info->plain_body);
        g_free (info->html_body);
        g_free (info->subject);
+       g_free (info->references);
+       g_free (info->in_reply_to);
        g_list_foreach (info->attachments_list, (GFunc) g_object_unref, NULL);
        g_list_free (info->attachments_list);
        g_list_foreach (info->images_list, (GFunc) g_object_unref, NULL);
@@ -900,6 +909,8 @@ modest_mail_operation_create_msg (ModestMailOperation *self,
                                  const GList *attachments_list,
                                  const GList *images_list,
                                  TnyHeaderFlags priority_flags,
+                                 const gchar *references,
+                                 const gchar *in_reply_to,
                                  ModestMailOperationCreateMsgCallback callback,
                                  gpointer userdata)
 {
@@ -915,6 +926,8 @@ modest_mail_operation_create_msg (ModestMailOperation *self,
        info->subject = g_strdup (subject);
        info->plain_body = g_strdup (plain_body);
        info->html_body = g_strdup (html_body);
+       info->references = g_strdup (references);
+       info->in_reply_to = g_strdup (in_reply_to);
        info->attachments_list = g_list_copy ((GList *) attachments_list);
        g_list_foreach (info->attachments_list, (GFunc) g_object_ref, NULL);
        info->images_list = g_list_copy ((GList *) images_list);
@@ -1074,6 +1087,8 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
                                     const gchar *html_body,
                                     const GList *attachments_list,
                                     const GList *images_list,
+                                    const gchar *references,
+                                    const gchar *in_reply_to,
                                     TnyHeaderFlags priority_flags)
 {
        ModestMailOperationPrivate *priv = NULL;
@@ -1110,6 +1125,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
 
        modest_mail_operation_create_msg (self, from, to, cc, bcc, subject, plain_body, html_body,
                                          attachments_list, images_list, priority_flags,
+                                         references, in_reply_to,
                                          modest_mail_operation_send_new_mail_cb, info);
 
 }
@@ -1272,6 +1288,8 @@ modest_mail_operation_save_to_drafts (ModestMailOperation *self,
                                      const GList *attachments_list,
                                      const GList *images_list,
                                      TnyHeaderFlags priority_flags,
+                                     const gchar *references,
+                                     const gchar *in_reply_to,
                                      SaveToDraftstCallback callback,
                                      gpointer user_data)
 {
@@ -1297,6 +1315,7 @@ modest_mail_operation_save_to_drafts (ModestMailOperation *self,
        modest_mail_operation_notify_start (self);
        modest_mail_operation_create_msg (self, from, to, cc, bcc, subject, plain_body, html_body,
                                          attachments_list, images_list, priority_flags,
+                                         references, in_reply_to,
                                          modest_mail_operation_save_to_drafts_cb, info);
 }
 
index e57e9d4..997104b 100644 (file)
@@ -381,6 +381,8 @@ void    modest_mail_operation_send_new_mail   (ModestMailOperation *self,
                                               const gchar *html_body,
                                               const GList *attachments_list,
                                               const GList *images_list,
+                                              const gchar *references,
+                                              const gchar *in_reply_to,
                                               TnyHeaderFlags priority_flags);
 
 
@@ -420,6 +422,8 @@ void modest_mail_operation_save_to_drafts   (ModestMailOperation *self,
                                             const GList *attachments_list,
                                             const GList *images_list,
                                             TnyHeaderFlags priority_flags,
+                                            const gchar *references,
+                                            const gchar *in_reply_to,
                                             SaveToDraftstCallback callback,
                                             gpointer user_data);
 /**
index ba5c456..7f3a030 100644 (file)
@@ -61,7 +61,9 @@ static gboolean is_ascii(const gchar *s);
 
 TnyMsg*
 modest_tny_msg_new (const gchar* mailto, const gchar* from, const gchar *cc,
-                   const gchar *bcc, const gchar* subject, const gchar *body,
+                   const gchar *bcc, const gchar* subject, 
+                   const gchar *references, const gchar *in_reply_to,
+                   const gchar *body,
                    GList *attachments, gint *attached, GError **err)
 {
        TnyMsg *new_msg;
@@ -98,6 +100,12 @@ modest_tny_msg_new (const gchar* mailto, const gchar* from, const gchar *cc,
         */
        tny_mime_part_set_header_pair (TNY_MIME_PART (new_msg), "X-Mailer", "Modest "
                                       VERSION);
+
+       if (references)
+               tny_mime_part_set_header_pair (TNY_MIME_PART (new_msg), "References", references);
+
+       if (in_reply_to)
+               tny_mime_part_set_header_pair (TNY_MIME_PART (new_msg), "In-Reply-To", in_reply_to);
        
        /* Add the body of the new mail */
        /* This is needed even if body is NULL or empty. */
@@ -118,6 +126,7 @@ modest_tny_msg_new (const gchar* mailto, const gchar* from, const gchar *cc,
 TnyMsg*
 modest_tny_msg_new_html_plain (const gchar* mailto, const gchar* from, const gchar *cc,
                               const gchar *bcc, const gchar* subject, 
+                              const gchar *references, const gchar *in_reply_to,
                               const gchar *html_body, const gchar *plain_body,
                               GList *attachments, GList *images, gint *attached, GError **err)
 {
@@ -153,6 +162,12 @@ modest_tny_msg_new_html_plain (const gchar* mailto, const gchar* from, const gch
        tny_mime_part_set_header_pair (TNY_MIME_PART (new_msg), "X-Mailer", "Modest "
                                       VERSION);
 
+       if (references)
+               tny_mime_part_set_header_pair (TNY_MIME_PART (new_msg), "References", references);
+
+       if (in_reply_to)
+               tny_mime_part_set_header_pair (TNY_MIME_PART (new_msg), "In-Reply-To", in_reply_to);
+       
        /* Add the body of the new mail */      
        add_body_part (new_msg, plain_body, content_type);
        add_html_body_part (new_msg, html_body);
@@ -840,6 +855,108 @@ get_new_cc (TnyHeader *header, const gchar* from)
        return result;
 }
 
+void 
+modest_tny_msg_get_references (TnyMsg *msg, gchar **message_id, gchar **references, gchar **in_reply_to)
+{
+       TnyList *headers;
+       TnyIterator *iterator;
+       gchar *l_message_id;
+       gchar *l_references;
+       gchar *l_in_reply_to;
+
+       g_return_if_fail (TNY_IS_MSG (msg));
+
+       l_message_id = NULL;
+       l_references = NULL;
+       l_in_reply_to = NULL;
+
+       headers = TNY_LIST (tny_simple_list_new ());
+       tny_mime_part_get_header_pairs (TNY_MIME_PART (msg), headers);
+
+       iterator = tny_list_create_iterator (headers);
+       while (!tny_iterator_is_done (iterator)) {
+               TnyPair *pair;
+               const gchar *name;
+
+               pair = TNY_PAIR (tny_iterator_get_current (iterator));
+               name = tny_pair_get_name (pair);
+               if (!g_strcasecmp (name, "References")) {
+                       if (l_references) g_free (l_references);
+                       l_references = g_strdup (tny_pair_get_value (pair));
+               } else if (!g_strcasecmp (name, "In-Reply-To")) {
+                       if (l_in_reply_to) g_free (l_in_reply_to);
+                       l_in_reply_to = g_strdup (tny_pair_get_value (pair));
+               } else if (!g_strcasecmp (name, "Message-ID")) {
+                       if (l_message_id) g_free (l_message_id);
+                       l_message_id = g_strdup (tny_pair_get_value (pair));
+               }
+
+               g_object_unref (pair);
+               tny_iterator_next (iterator);
+       }
+
+       g_object_unref (iterator);
+       g_object_unref (headers);
+
+       if (message_id) {
+               *message_id = l_message_id;
+       } else {
+               g_free (l_message_id);
+       }
+
+       if (in_reply_to) {
+               *in_reply_to = l_in_reply_to;
+       } else {
+               g_free (l_in_reply_to);
+       }
+
+       if (references) {
+               *references = l_references;
+       } else {
+               g_free (l_references);
+       }
+}
+
+static void 
+set_references (TnyMsg *reply_msg, TnyMsg *original_msg)
+{
+       gchar *orig_references, *orig_in_reply_to, *orig_message_id;
+       gchar *references, *in_reply_to;
+
+       modest_tny_msg_get_references (original_msg, &orig_message_id, &orig_references, &orig_in_reply_to);
+
+       references = NULL;
+       in_reply_to = NULL;
+
+       if (orig_message_id)
+               in_reply_to = g_strdup (orig_message_id);
+
+       if (orig_references) {
+               if (orig_message_id)
+                       references = g_strconcat (orig_references, "\n        ", orig_message_id, NULL);
+               else
+                       references = g_strdup (orig_references);
+
+       } else if (orig_in_reply_to) {
+               if (orig_message_id)
+                       references = g_strconcat (orig_in_reply_to, "\n        ", orig_message_id, NULL);
+               else
+                       references = g_strdup (orig_in_reply_to);
+       } else if (orig_message_id) {
+               references = g_strdup (orig_message_id);
+       }
+
+       g_free (orig_references);
+       g_free (orig_in_reply_to);
+       g_free (orig_message_id);
+
+       if (in_reply_to) {
+               tny_mime_part_set_header_pair (TNY_MIME_PART (reply_msg), "In-Reply-To", in_reply_to);
+       }
+       if (references) {
+               tny_mime_part_set_header_pair (TNY_MIME_PART (reply_msg), "References", references);
+       }
+}
 
 TnyMsg* 
 modest_tny_msg_create_reply_msg (TnyMsg *msg,
@@ -863,6 +980,8 @@ modest_tny_msg_create_reply_msg (TnyMsg *msg,
 
        new_msg = create_reply_forward_mail (msg, header, from, signature, TRUE, reply_type,
                                             attachments_list);
+
+       set_references (new_msg, msg);
        if (attachments_list != NULL) {
                g_list_foreach (attachments_list, (GFunc) g_object_unref, NULL);
                g_list_free (attachments_list);
index 91ae148..fabbafb 100644 (file)
@@ -78,7 +78,9 @@ typedef enum _ModestTnyMsgReplyMode {
  * Returns: a new TnyMsg (free with g_object_unref)
  */     
 TnyMsg* modest_tny_msg_new (const gchar* mailto, const gchar* mailfrom, const gchar *cc,
-                           const gchar *bcc, const gchar* subject, const gchar *body,
+                           const gchar *bcc, const gchar* subject, 
+                           const gchar *references, const gchar *in_reply_to,
+                           const gchar *body,
                            GList *attachments, gint *attached, GError **err);
 
 /**
@@ -100,7 +102,8 @@ TnyMsg* modest_tny_msg_new (const gchar* mailto, const gchar* mailfrom, const gc
  * Returns: a new TnyMsg (free with g_object_unref)
  */     
 TnyMsg* modest_tny_msg_new_html_plain (const gchar* mailto, const gchar* mailfrom, const gchar *cc,
-                                      const gchar *bcc, const gchar* subject, 
+                                      const gchar *bcc, const gchar* subject,
+                                      const gchar *references, const gchar *in_reply_to,
                                       const gchar *html_body, const gchar *plain_body,
                                       GList *attachments, GList *images, gint *attached, GError **err);
 
@@ -219,5 +222,17 @@ modest_tny_msg_header_get_all_recipients_list (TnyHeader *header);
 GSList *
 modest_tny_msg_get_all_recipients_list (TnyMsg *msg);
 
+/**
+ * modest_tny_msg_get_references:
+ * @msg: a #TnyMsg
+ * @message_id: a pointer to a string
+ * @references: a pointer to a string
+ * @in_reply_to: a pointer to a string
+ *
+ * obtains the Message-ID, References and In-Reply-To fields of a
+ * message
+ */
+void modest_tny_msg_get_references (TnyMsg *msg, gchar **message_id, gchar **references, gchar **in_reply_to);
+
 
 #endif /* __MODEST_TNY_MSG_H__ */
index e342e7f..417a11e 100644 (file)
@@ -832,7 +832,7 @@ modest_ui_actions_compose_msg(ModestWindow *win,
                body = use_signature ? g_strconcat("\n--\n", signature, NULL) : g_strdup("");
        }
 
-       msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL, NULL);
+       msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, NULL, NULL, body, NULL, NULL, NULL);
        if (!msg) {
                g_printerr ("modest: failed to create new msg\n");
                goto cleanup;
@@ -2920,6 +2920,8 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                                              data->attachments,
                                              data->images,
                                              data->priority_flags,
+                                             data->references,
+                                             data->in_reply_to,
                                              on_save_to_drafts_cb,
                                              g_object_ref(edit_window));
 
@@ -3066,6 +3068,8 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
                                             data->html_body,
                                             data->attachments,
                                             data->images,
+                                            data->references,
+                                            data->in_reply_to,
                                             data->priority_flags);
 
        if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
index 94a6898..4012ac9 100644 (file)
@@ -97,6 +97,7 @@ typedef enum {
  */
 typedef struct  {
        gchar *from, *to, *cc, *bcc, *subject, *plain_body, *html_body;
+       gchar *references, *in_reply_to;
        GList *attachments;
        GList *images;
        TnyHeaderFlags priority_flags;