* src/modest-tny-msg.[ch]:
authorJose Dapena Paz <jdapena@igalia.com>
Fri, 30 May 2008 16:10:52 +0000 (16:10 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Fri, 30 May 2008 16:10:52 +0000 (16:10 +0000)
        * 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
src/modest-tny-msg.c
src/modest-tny-msg.h
src/modest-ui-actions.c

index 8b38cd6..41a8a89 100644 (file)
@@ -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));
index 9aeb40d..0bb700b 100644 (file)
@@ -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
index 9d61204..a15372b 100644 (file)
@@ -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:
index a2a3a31..6b08023 100644 (file)
@@ -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;