From ac50c4b59461225aa321ffadaa27be00a6402be3 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Mon, 30 Jul 2007 13:07:41 +0000 Subject: [PATCH] * src/modest-tny-msg.[ch]: * (create_reply_forward_mail): now get a TnyHeader attribute for the case we don't have a full TnyMsg available. * (modest_tny_msg_create_forward_msg): use the new create_reply_forward_mail api. * (modest_tny_msg_create_reply_msg): now it gets a TnyHeader parameter for the case there's no TnyMsg available (it should happen at least on replying without original message in main window. * src/modest-ui-actions.c: * (reply_forward_cb): uses the new modest_tny_msg_create_reply_msg api. * (reply_forward_cb): now we don't free the header parameter in this callback, as this should be done by callers. * (reply_forward): now we don't show the retrieve confirmation dialog on replying without original message in reply. We don't retrieve the original message too (fixes NB#63674). pmo-trunk-r2849 --- src/modest-tny-msg.c | 43 ++++++++++++++++++++----------- src/modest-tny-msg.h | 6 +++-- src/modest-ui-actions.c | 64 ++++++++++++++++++++++++++--------------------- 3 files changed, 67 insertions(+), 46 deletions(-) diff --git a/src/modest-tny-msg.c b/src/modest-tny-msg.c index 73df2d0..6278399 100644 --- a/src/modest-tny-msg.c +++ b/src/modest-tny-msg.c @@ -398,20 +398,25 @@ modest_tny_msg_find_body_part (TnyMsg *msg, gboolean want_html) static TnyMsg * -create_reply_forward_mail (TnyMsg *msg, const gchar *from, const gchar *signature, +create_reply_forward_mail (TnyMsg *msg, TnyHeader *header, const gchar *from, const gchar *signature, gboolean is_reply, guint type, GList *attachments) { TnyMsg *new_msg; - TnyHeader *new_header, *header; + TnyHeader *new_header; gchar *new_subject; - TnyMimePart *body; + TnyMimePart *body = NULL; ModestFormatter *formatter; gchar *subject_prefix; /* Get body from original msg. Always look for the text/plain part of the message to create the reply/forwarded mail */ - header = tny_msg_get_header (msg); - body = modest_tny_msg_find_body_part (msg, FALSE); + if (header) + g_object_ref (header); + else + header = tny_msg_get_header (msg); + + if (msg != NULL) + body = modest_tny_msg_find_body_part (msg, FALSE); /* TODO: select the formatter from account prefs */ if (modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_PREFER_FORMATTED_TEXT, NULL)) @@ -442,7 +447,8 @@ create_reply_forward_mail (TnyMsg *msg, const gchar *from, const gchar *signatur } } g_object_unref (G_OBJECT(formatter)); - g_object_unref (G_OBJECT(body)); + if (body) + g_object_unref (G_OBJECT(body)); /* Fill the header */ new_header = tny_msg_get_header (new_msg); @@ -498,7 +504,7 @@ modest_tny_msg_create_forward_msg (TnyMsg *msg, tny_mime_part_get_parts (TNY_MIME_PART (msg), parts); tny_list_foreach (parts, add_if_attachment, &attachments_list); - new_msg = create_reply_forward_mail (msg, from, signature, FALSE, forward_type, attachments_list); + new_msg = create_reply_forward_mail (msg, NULL, from, signature, FALSE, forward_type, attachments_list); add_attachments (new_msg, attachments_list); /* Clean */ @@ -510,14 +516,15 @@ modest_tny_msg_create_forward_msg (TnyMsg *msg, } TnyMsg* -modest_tny_msg_create_reply_msg (TnyMsg *msg, +modest_tny_msg_create_reply_msg (TnyMsg *msg, + TnyHeader *header, const gchar *from, const gchar *signature, ModestTnyMsgReplyType reply_type, ModestTnyMsgReplyMode reply_mode) { TnyMsg *new_msg = NULL; - TnyHeader *new_header, *header; + TnyHeader *new_header; const gchar* reply_to; gchar *new_cc = NULL; const gchar *cc = NULL, *bcc = NULL; @@ -526,19 +533,25 @@ modest_tny_msg_create_reply_msg (TnyMsg *msg, GList *attachments_list = NULL; /* Add attachments */ - parts = TNY_LIST (tny_simple_list_new()); - tny_mime_part_get_parts (TNY_MIME_PART (msg), parts); - tny_list_foreach (parts, add_if_attachment, &attachments_list); + if (msg != NULL) { + parts = TNY_LIST (tny_simple_list_new()); + tny_mime_part_get_parts (TNY_MIME_PART (msg), parts); + tny_list_foreach (parts, add_if_attachment, &attachments_list); + } - new_msg = create_reply_forward_mail (msg, from, signature, TRUE, reply_type, attachments_list); + new_msg = create_reply_forward_mail (msg, header, from, signature, TRUE, reply_type, attachments_list); if (attachments_list) { g_list_foreach (attachments_list, (GFunc) g_object_unref, NULL); g_list_free (attachments_list); } - g_object_unref (G_OBJECT (parts)); + if (parts) + g_object_unref (G_OBJECT (parts)); /* Fill the header */ - header = tny_msg_get_header (msg); + if (header) + g_object_ref (header); + else + header = tny_msg_get_header (msg); new_header = tny_msg_get_header (new_msg); reply_to = tny_header_get_replyto (header); diff --git a/src/modest-tny-msg.h b/src/modest-tny-msg.h index 14133b5..5bf4276 100644 --- a/src/modest-tny-msg.h +++ b/src/modest-tny-msg.h @@ -145,7 +145,8 @@ TnyMsg* modest_tny_msg_create_forward_msg (TnyMsg *msg, /** * modest_tny_msg_create_reply_msg: - * @msg: a valid #TnyMsg instance + * @msg: a valid #TnyMsg instance, or %NULL + * @header: a valid #TnyHeader instance, or %NULL * @from: the sender of the forwarded mail * @signature: signature to add to the reply message * @reply_type: the type of formatting used to create the reply message @@ -155,7 +156,8 @@ TnyMsg* modest_tny_msg_create_forward_msg (TnyMsg *msg, * * Returns: Returns: a new #TnyMsg, or NULL in case of error **/ -TnyMsg* modest_tny_msg_create_reply_msg (TnyMsg *msg, +TnyMsg* modest_tny_msg_create_reply_msg (TnyMsg *msg, + TnyHeader *header, const gchar *from, const gchar *signature, ModestTnyMsgReplyType reply_type, diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 7d397c5..e20e028 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -1043,13 +1043,13 @@ reply_forward_cb (ModestMailOperation *mail_op, switch (rf_helper->action) { case ACTION_REPLY: new_msg = - modest_tny_msg_create_reply_msg (msg, from, signature, + modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type, MODEST_TNY_MSG_REPLY_MODE_SENDER); break; case ACTION_REPLY_TO_ALL: new_msg = - modest_tny_msg_create_reply_msg (msg, from, signature, rf_helper->reply_forward_type, + modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type, MODEST_TNY_MSG_REPLY_MODE_ALL); edit_type = MODEST_EDIT_TYPE_REPLY; break; @@ -1101,7 +1101,6 @@ cleanup: if (account) g_object_unref (G_OBJECT (account)); /* g_object_unref (msg); */ - g_object_unref (header); free_reply_forward_helper (rf_helper); } @@ -1172,7 +1171,8 @@ reply_forward (ReplyForwardAction action, ModestWindow *win) TnyList *header_list = NULL; ReplyForwardHelper *rf_helper = NULL; guint reply_forward_type; - gboolean continue_download; + gboolean continue_download = TRUE; + gboolean do_retrieve = TRUE; g_return_if_fail (MODEST_IS_WINDOW(win)); @@ -1186,17 +1186,20 @@ reply_forward (ReplyForwardAction action, ModestWindow *win) if (!header_list) return; + reply_forward_type = + modest_conf_get_int (modest_runtime_get_conf (), + (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE, + NULL); + /* Check that the messages have been previously downloaded */ - continue_download = download_uncached_messages (header_list, GTK_WINDOW (win), TRUE); + do_retrieve = (action == ACTION_FORWARD) || (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE); + if (do_retrieve) + continue_download = download_uncached_messages (header_list, GTK_WINDOW (win), TRUE); if (!continue_download) { g_object_unref (header_list); return; } - reply_forward_type = - modest_conf_get_int (modest_runtime_get_conf (), - (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE, - NULL); /* We assume that we can only select messages of the same folder and that we reply all of them from the same account. In fact the interface currently only @@ -1224,46 +1227,49 @@ reply_forward (ReplyForwardAction action, ModestWindow *win) if (!msg || !header) { if (msg) g_object_unref (msg); - if (header) - g_object_unref (header); g_printerr ("modest: no message found\n"); return; } else { reply_forward_cb (NULL, header, msg, rf_helper); } + if (header) + g_object_unref (header); } else { TnyHeader *header; TnyIterator *iter; - /* Retrieve messages */ - mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, - G_OBJECT(win), - modest_ui_actions_get_msgs_full_error_handler, - NULL); - modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); - /* Only reply/forward to one message */ iter = tny_list_create_iterator (header_list); header = TNY_HEADER (tny_iterator_get_current (iter)); g_object_unref (iter); if (header) { - modest_mail_operation_get_msg (mail_op, - header, - reply_forward_cb, - rf_helper); + /* Retrieve messages */ + if (do_retrieve) { + mail_op = modest_mail_operation_new_with_error_handling ( + MODEST_MAIL_OPERATION_TYPE_RECEIVE, + G_OBJECT(win), + modest_ui_actions_get_msgs_full_error_handler, + NULL); + modest_mail_operation_queue_add ( + modest_runtime_get_mail_operation_queue (), mail_op); + + modest_mail_operation_get_msg (mail_op, + header, + reply_forward_cb, + rf_helper); + /* Clean */ + g_object_unref(mail_op); + } else { + /* we put a ref here to prevent double unref as the reply + * forward callback unrefs the header at its end */ + reply_forward_cb (NULL, header, NULL, rf_helper); + } -/* modest_mail_operation_get_msgs_full (mail_op, */ -/* header_list, */ -/* reply_forward_cb, */ -/* rf_helper, */ -/* free_reply_forward_helper); */ g_object_unref (header); } - /* Clean */ - g_object_unref(mail_op); } /* Free */ -- 1.7.9.5