From 0fd7e1f7c631aa932f8931e33496960957dba074 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Fri, 30 May 2008 16:10:52 +0000 Subject: [PATCH] * src/modest-tny-msg.[ch]: * Now add_attachments method counts the number of attachments really attached (attachments we fail to retrieve are not counted), so that we can decide if we set the attachments flag This changes a bit the methods to create messages. * src/modest-mail-operation.c: * Only set attachment flags if any attachment has been added succesfully (fixes NB#85360). * src/modest-ui-actions.c: * Adapt to changes in tny msg builders. pmo-trunk-r4588 --- src/modest-mail-operation.c | 7 ++++--- src/modest-tny-msg.c | 21 +++++++++++++++------ src/modest-tny-msg.h | 8 +++++--- src/modest-ui-actions.c | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 8b38cd6..41a8a89 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -701,18 +701,19 @@ create_msg_thread (gpointer thread_data) CreateMsgInfo *info = (CreateMsgInfo *) thread_data; TnyMsg *new_msg = NULL; ModestMailOperationPrivate *priv; + gint attached = 0; 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->attachments_list, + 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->plain_body, info->attachments_list, - info->images_list, + info->images_list, &attached, &(priv->error)); } @@ -724,7 +725,7 @@ create_msg_thread (gpointer thread_data) tny_header_set_flag (header, info->priority_flags); /* Set attachment flags in message */ - if (info->attachments_list != NULL) + if (info->attachments_list != NULL && attached > 0) tny_header_set_flag (header, TNY_HEADER_FLAG_ATTACHMENTS); g_object_unref (G_OBJECT(header)); diff --git a/src/modest-tny-msg.c b/src/modest-tny-msg.c index 9aeb40d..0bb700b 100644 --- a/src/modest-tny-msg.c +++ b/src/modest-tny-msg.c @@ -52,7 +52,7 @@ static TnyMimePart * add_body_part (TnyMsg *msg, const gchar *body, const gchar *content_type); static TnyMimePart * add_html_body_part (TnyMsg *msg, const gchar *body); -static void add_attachments (TnyMimePart *part, GList *attachments_list, gboolean add_inline, GError **err); +static gint add_attachments (TnyMimePart *part, GList *attachments_list, gboolean add_inline, GError **err); static void add_images (TnyMsg *msg, GList *attachments_list, GError **err); static char * get_content_type(const gchar *s); static gboolean is_ascii(const gchar *s); @@ -61,11 +61,12 @@ 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, - GList *attachments, GError **err) + GList *attachments, gint *attached, GError **err) { TnyMsg *new_msg; TnyHeader *header; gchar *content_type; + gint tmp_attached = 0; /* Create new msg */ new_msg = modest_formatter_create_message (NULL, TRUE, (attachments != NULL), FALSE); @@ -101,7 +102,9 @@ modest_tny_msg_new (const gchar* mailto, const gchar* from, const gchar *cc, /* Add attachments */ if (attachments) - add_attachments (TNY_MIME_PART (new_msg), attachments, FALSE, err); + tmp_attached = add_attachments (TNY_MIME_PART (new_msg), attachments, FALSE, err); + if (attached) + *attached = tmp_attached; if (header) g_object_unref(header); @@ -112,11 +115,12 @@ TnyMsg* modest_tny_msg_new_html_plain (const gchar* mailto, const gchar* from, const gchar *cc, const gchar *bcc, const gchar* subject, const gchar *html_body, const gchar *plain_body, - GList *attachments, GList *images, GError **err) + GList *attachments, GList *images, gint *attached, GError **err) { TnyMsg *new_msg; TnyHeader *header; gchar *content_type; + gint tmp_attached; /* Create new msg */ new_msg = modest_formatter_create_message (NULL, FALSE, (attachments != NULL), (images != NULL)); @@ -151,7 +155,9 @@ modest_tny_msg_new_html_plain (const gchar* mailto, const gchar* from, const gch g_free (content_type); /* Add attachments */ - add_attachments (TNY_MIME_PART (new_msg), attachments, FALSE, err); + tmp_attached = add_attachments (TNY_MIME_PART (new_msg), attachments, FALSE, err); + if (attached) + *attached = tmp_attached; add_images (new_msg, images, err); if (header) g_object_unref(header); @@ -297,12 +303,13 @@ copy_mime_part (TnyMimePart *part, GError **err) return result; } -static void +static gint add_attachments (TnyMimePart *part, GList *attachments_list, gboolean add_inline, GError **err) { GList *pos; TnyMimePart *attachment_part, *old_attachment; gint ret; + gint attached = 0; for (pos = (GList *)attachments_list; pos; pos = pos->next) { @@ -326,12 +333,14 @@ add_attachments (TnyMimePart *part, GList *attachments_list, gboolean add_inline } tny_mime_part_set_transfer_encoding (TNY_MIME_PART (attachment_part), "base64"); ret = tny_mime_part_add_part (TNY_MIME_PART (part), attachment_part); + attached++; if (old_cid) tny_mime_part_set_content_id (attachment_part, old_cid); g_object_unref (attachment_part); } } } + return attached; } static void diff --git a/src/modest-tny-msg.h b/src/modest-tny-msg.h index 9d61204..a15372b 100644 --- a/src/modest-tny-msg.h +++ b/src/modest-tny-msg.h @@ -70,6 +70,7 @@ typedef enum _ModestTnyMsgReplyMode { * @subject: subject for the messdage * @body: body for the message * @attachments: a list of attachments (local URIs) + * @attached: a #gint pointer, returns the number of attachments really included. * @error: a pointer for errors in message creation * * create a new TnyMsg with the given parameters @@ -78,7 +79,7 @@ typedef enum _ModestTnyMsgReplyMode { */ TnyMsg* modest_tny_msg_new (const gchar* mailto, const gchar* mailfrom, const gchar *cc, const gchar *bcc, const gchar* subject, const gchar *body, - GList *attachments, GError **err); + GList *attachments, gint *attached, GError **err); /** * modest_tny_msg_new_html_plain: @@ -90,7 +91,8 @@ TnyMsg* modest_tny_msg_new (const gchar* mailto, const gchar* mailfrom, const gc * @html_body: body for the message in HTML * @plain_body: body for the message in plain text * @attachments: a list of attachments (mime parts) - * @attachments: a list of images (mime parts) + * @images: a list of images (mime parts) + * @attached: a #gint pointer, returns the number of attachments really included. * @error: a pointer for errors in message creation * * create a new TnyMsg with the given parameters @@ -100,7 +102,7 @@ TnyMsg* modest_tny_msg_new (const gchar* mailto, const gchar* mailfrom, const gc TnyMsg* modest_tny_msg_new_html_plain (const gchar* mailto, const gchar* mailfrom, const gchar *cc, const gchar *bcc, const gchar* subject, const gchar *html_body, const gchar *plain_body, - GList *attachments, GList *images, GError **err); + GList *attachments, GList *images, gint *attached, GError **err); /** * modest_tny_msg_find_body_part: diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index a2a3a31..6b08023 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -733,7 +733,7 @@ modest_ui_actions_compose_msg(ModestWindow *win, body = use_signature ? g_strconcat("\n", signature, NULL) : g_strdup(""); } - msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL); + msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL, NULL); if (!msg) { g_printerr ("modest: failed to create new msg\n"); goto cleanup; -- 1.7.9.5