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))
}
}
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);
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 */
}
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;
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);
/**
* 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
*
* 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,
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;
if (account)
g_object_unref (G_OBJECT (account));
/* g_object_unref (msg); */
- g_object_unref (header);
free_reply_forward_helper (rf_helper);
}
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));
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
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 */