[evolution-mapi/gnome-3-8] Bug #700885 - Message size is 0 when downloading for offline



commit 413e9614527024262e5f0111ea126a639b15d431
Author: Milan Crha <mcrha redhat com>
Date:   Tue Aug 6 11:38:00 2013 +0200

    Bug #700885 - Message size is 0 when downloading for offline

 src/camel/camel-mapi-folder.c              |   48 ++++++++++++++++++++++-----
 src/libexchangemapi/e-mapi-connection.c    |   14 +++++++-
 src/libexchangemapi/e-mapi-fast-transfer.c |    2 +-
 src/libexchangemapi/e-mapi-mail-utils.c    |    8 +++-
 4 files changed, 58 insertions(+), 14 deletions(-)
---
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index 7031899..ef8ee03 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -393,6 +393,13 @@ update_message_info (CamelMessageInfo *info,
        pread_receipt = e_mapi_util_find_array_propval (&object->properties, PidTagReadReceiptRequested);
        msg_class = e_mapi_util_find_array_propval (&object->properties, PidTagMessageClass);
 
+       if (!minfo->info.size) {
+               const uint32_t *msg_size;
+
+               msg_size = e_mapi_util_find_array_propval (&object->properties, PidTagMessageSize);
+               minfo->info.size = msg_size ? *msg_size : 0;
+       }
+
        if (msg_class && g_str_has_prefix (msg_class, "REPORT.IPM.Note.IPNRN"))
                pread_receipt = NULL;
 
@@ -439,6 +446,26 @@ update_message_info (CamelMessageInfo *info,
        camel_folder_summary_touch (minfo->info.summary);
 }
 
+static gsize
+camel_mapi_get_message_size (CamelMimeMessage *msg)
+{
+       CamelStream *null;
+       CamelDataWrapper *dw;
+       gsize sz;
+
+       if (!CAMEL_IS_DATA_WRAPPER (msg))
+               return 0;
+
+       dw = CAMEL_DATA_WRAPPER (msg);
+       null = camel_stream_null_new ();
+       /* do not 'decode', let's be interested in the raw message size */
+       camel_data_wrapper_write_to_stream_sync (dw, null, NULL, NULL);
+       sz = CAMEL_STREAM_NULL (null)->written;
+       g_object_unref (null);
+
+       return sz;
+}
+
 struct GatherObjectSummaryData
 {
        CamelFolder *folder;
@@ -461,14 +488,14 @@ remove_removed_uids_cb (gpointer uid_str, gpointer value, gpointer user_data)
 }
 
 static gboolean
-gather_object_offline_cb (EMapiConnection *conn,
-                         TALLOC_CTX *mem_ctx,
-                         /* const */ EMapiObject *object,
-                         guint32 obj_index,
-                         guint32 obj_total,
-                         gpointer user_data,
-                         GCancellable *cancellable,
-                         GError **perror)
+gather_object_for_offline_cb (EMapiConnection *conn,
+                             TALLOC_CTX *mem_ctx,
+                             /* const */ EMapiObject *object,
+                             guint32 obj_index,
+                             guint32 obj_total,
+                             gpointer user_data,
+                             GCancellable *cancellable,
+                             GError **perror)
 {
        struct GatherObjectSummaryData *gos = user_data;
        CamelMimeMessage *msg;
@@ -524,6 +551,9 @@ gather_object_offline_cb (EMapiConnection *conn,
 
                        update_message_info (info, object, is_new, gos->is_public_folder, user_has_read);
 
+                       if (!minfo->info.size)
+                               minfo->info.size = camel_mapi_get_message_size (msg);
+
                        camel_folder_summary_add (gos->folder->summary, info);
                        camel_message_info_ref (info);
 
@@ -844,7 +874,7 @@ camel_mapi_folder_fetch_summary (CamelFolder *folder, GCancellable *cancellable,
                if (full_download) {
                        camel_operation_push_message (cancellable, _("Downloading messages in folder '%s'"), 
camel_folder_get_display_name (folder));
 
-                       status = e_mapi_connection_transfer_objects (conn, &obj_folder, gco.to_update, 
gather_object_offline_cb, &gos, cancellable, mapi_error);
+                       status = e_mapi_connection_transfer_objects (conn, &obj_folder, gco.to_update, 
gather_object_for_offline_cb, &gos, cancellable, mapi_error);
 
                        camel_operation_pop_message (cancellable);
                } else {
diff --git a/src/libexchangemapi/e-mapi-connection.c b/src/libexchangemapi/e-mapi-connection.c
index 26205d7..048ea99 100644
--- a/src/libexchangemapi/e-mapi-connection.c
+++ b/src/libexchangemapi/e-mapi-connection.c
@@ -2452,6 +2452,7 @@ ensure_additional_properties_cb (EMapiConnection *conn,
                uint32_t orig_proptag, use_proptag;
        } additional_properties[] = {
                { PidTagBody, MAPI_E_RESERVED },
+               { PidTagMessageSize, MAPI_E_RESERVED },
                { PidNameContentClass, MAPI_E_RESERVED }
        };
        struct EnsureAdditionalPropertiesData *eap = user_data;
@@ -2462,6 +2463,9 @@ ensure_additional_properties_cb (EMapiConnection *conn,
        g_return_val_if_fail (eap->cb != NULL, FALSE);
        g_return_val_if_fail (object != NULL, FALSE);
 
+       if (g_cancellable_is_cancelled (cancellable))
+               return FALSE;
+
        for (ii = 0; ii < G_N_ELEMENTS (additional_properties); ii++) {
                uint32_t prop = additional_properties[ii].orig_proptag;
 
@@ -2478,7 +2482,7 @@ ensure_additional_properties_cb (EMapiConnection *conn,
        }
 
        /* Fast-transfer transfers only Html or Body, never both */
-       if (need_any || has_embedded_message_without_body (object)) {
+       if (!g_cancellable_is_cancelled (cancellable) && (need_any || has_embedded_message_without_body 
(object))) {
                const mapi_id_t *mid;
 
                mid = e_mapi_util_find_array_propval (&object->properties, PidTagMid);
@@ -3074,7 +3078,10 @@ e_mapi_connection_transfer_objects (EMapiConnection *conn,
                                mapi_id_array_add_id (&ids, *pmid);
                }
 
-               if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+               if (g_cancellable_is_cancelled (cancellable)) {
+                       if (perror && !*perror)
+                               g_cancellable_set_error_if_cancelled (cancellable, perror);
+
                        ms = MAPI_E_USER_CANCEL;
                        mapi_id_array_release (&ids);
                        goto cleanup;
@@ -3154,6 +3161,9 @@ internal_get_summary_cb (EMapiConnection *conn,
        g_return_val_if_fail (gsd->cb != NULL, FALSE);
        g_return_val_if_fail (object != NULL, FALSE);
 
+       if (g_cancellable_is_cancelled (cancellable))
+               return FALSE;
+
        /* also include properties received from GetProps,
           as those like PR_MID are not included by default */
        if (gsd->lpProps && gsd->prop_count > 0) {
diff --git a/src/libexchangemapi/e-mapi-fast-transfer.c b/src/libexchangemapi/e-mapi-fast-transfer.c
index d680692..298839b 100644
--- a/src/libexchangemapi/e-mapi-fast-transfer.c
+++ b/src/libexchangemapi/e-mapi-fast-transfer.c
@@ -420,7 +420,7 @@ e_mapi_fast_transfer_internal (EMapiConnection *conn,
                if (ms != MAPI_E_SUCCESS)
                        break;
 
-               if (g_cancellable_set_error_if_cancelled (cancellable, perror)) {
+               if (g_cancellable_is_cancelled (cancellable)) {
                        ms = MAPI_E_USER_CANCEL;
                        break;
                }
diff --git a/src/libexchangemapi/e-mapi-mail-utils.c b/src/libexchangemapi/e-mapi-mail-utils.c
index 7b97e10..9a50206 100644
--- a/src/libexchangemapi/e-mapi-mail-utils.c
+++ b/src/libexchangemapi/e-mapi-mail-utils.c
@@ -232,13 +232,17 @@ build_body_part_content (CamelMimePart *part, EMapiObject *object, uint32_t prop
                                str_cb = strlen (in_utf8);
                        }
 
-                       camel_mime_part_set_content (part, (const gchar *) str_lpb, str_cb, type);
+                       /* cannot set an empty content */
+                       if (!str_cb)
+                               camel_mime_part_set_content (part, " ", 1, type);
+                       else
+                               camel_mime_part_set_content (part, (const gchar *) str_lpb, str_cb, type);
                }
 
                g_free (in_utf8);
                g_free (buff);
        } else
-               camel_mime_part_set_content (part, " ", strlen (" "), "text/plain");
+               camel_mime_part_set_content (part, " ", 1, "text/plain");
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]