[evolution-ews] Bug 795329 - Fallback to message construction on ErrorMimeContentConversionFailed



commit 0013738d087f85e3b8ed45c753bd9ee0743fe877
Author: Milan Crha <mcrha redhat com>
Date:   Thu Apr 19 13:44:18 2018 +0200

    Bug 795329 - Fallback to message construction on ErrorMimeContentConversionFailed

 src/camel/camel-ews-folder.c |  223 +++++++++++++++++++++++++++++++++++++++++-
 src/camel/camel-ews-utils.c  |  200 ++++++++++++++++++++++----------------
 src/camel/camel-ews-utils.h  |    6 +
 src/server/e-ews-item.c      |   65 +++++--------
 4 files changed, 366 insertions(+), 128 deletions(-)
---
diff --git a/src/camel/camel-ews-folder.c b/src/camel/camel-ews-folder.c
index 2c0079e..f5d1173 100644
--- a/src/camel/camel-ews-folder.c
+++ b/src/camel/camel-ews-folder.c
@@ -504,6 +504,199 @@ ews_fetch_cancellable_cancelled_cb (GCancellable *cancellable,
        g_cond_broadcast (fetch_cond);
 }
 
+static gboolean
+ews_message_from_properties_sync (CamelEwsFolder *ews_folder,
+                                 EEwsConnection *cnc,
+                                 gint pri,
+                                 GSList *ids,
+                                 const gchar *mime_dir,
+                                 GSList **out_items, /* EEwsItem * */
+                                 GCancellable *cancellable,
+                                 GError **error)
+{
+       EEwsAdditionalProps *add_props;
+       const CamelNameValueArray *headers;
+       CamelMessageInfo *mi;
+       CamelMimeMessage *msg;
+       CamelStream *new_stream;
+       EEwsItem *item;
+       gboolean bval = FALSE;
+       gchar *mime_fname_new;
+       gint fd;
+       GSList *items = NULL;
+
+       g_return_val_if_fail (CAMEL_IS_EWS_FOLDER (ews_folder), FALSE);
+       g_return_val_if_fail (E_IS_EWS_CONNECTION (cnc), FALSE);
+       g_return_val_if_fail (ids != NULL, FALSE);
+       g_return_val_if_fail (mime_dir != NULL, FALSE);
+       g_return_val_if_fail (out_items != NULL, FALSE);
+
+       add_props = e_ews_additional_props_new ();
+       add_props->field_uri = g_strdup (SUMMARY_MESSAGE_PROPS " item:Body item:Attachments");
+       add_props->extended_furis = ews_folder_get_summary_message_mapi_flags ();
+
+       if (!e_ews_connection_get_items_sync (cnc, pri, ids, "IdOnly", add_props,
+               FALSE, NULL, E_EWS_BODY_TYPE_TEXT, &items, NULL, NULL, cancellable, error) || !items) {
+               e_ews_additional_props_free (add_props);
+               return FALSE;
+       }
+
+       e_ews_additional_props_free (add_props);
+
+       mi = camel_ews_utils_item_to_message_info (ews_folder, cnc, items->data, cancellable);
+       if (!mi) {
+               g_slist_free_full (items, g_object_unref);
+               return FALSE;
+       }
+
+       item = items->data;
+       msg = camel_mime_message_new ();
+
+       headers = camel_message_info_get_headers (mi);
+       if (headers) {
+               CamelMedium *medium = CAMEL_MEDIUM (msg);
+               guint ii, len;
+
+               len = camel_name_value_array_get_length (headers);
+
+               for (ii = 0; ii < len; ii++) {
+                       const gchar *name = NULL, *value = NULL;
+
+                       /* Skip any content-describing headers */
+                       if (camel_name_value_array_get (headers, ii, &name, &value) &&
+                           name && g_ascii_strncasecmp (name, "Content-", 8) != 0) {
+                               camel_medium_add_header (medium, name, value);
+                       }
+               }
+       } else {
+               CamelMedium *medium = CAMEL_MEDIUM (msg);
+
+               camel_mime_message_set_date (msg, e_ews_item_get_date_sent (item), 0);
+               camel_mime_message_set_message_id (msg, e_ews_item_get_msg_id (item));
+               if (e_ews_item_get_in_replyto (item))
+                       camel_medium_set_header (medium, "In-Reply-To", e_ews_item_get_in_replyto (item));
+               if (e_ews_item_get_references (item))
+                       camel_medium_set_header (medium, "References", e_ews_item_get_references (item));
+               camel_medium_set_header (medium, "From", camel_message_info_get_from (mi));
+               camel_medium_set_header (medium, "To", camel_message_info_get_to (mi));
+               camel_medium_set_header (medium, "Cc", camel_message_info_get_from (mi));
+               camel_mime_message_set_subject (msg, camel_message_info_get_subject (mi));
+       }
+
+       if (e_ews_item_has_attachments (item, &bval) && bval &&
+           e_ews_item_get_attachments_ids (item)) {
+               CamelMimePart *part;
+               CamelMultipart *m_mixed;
+               const gchar *body = e_ews_item_get_body (item);
+               GSList *attach_ids, *attachments = NULL, *link;
+
+               m_mixed = camel_multipart_new ();
+               camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (m_mixed), "multipart/mixed");
+               camel_multipart_set_boundary (m_mixed, NULL);
+
+               if (!body || !*body)
+                       body = " ";
+
+               part = camel_mime_part_new ();
+               camel_mime_part_set_encoding (part, CAMEL_TRANSFER_ENCODING_8BIT);
+               camel_mime_part_set_content (part, body, strlen (body), "text/plain");
+               camel_multipart_add_part (m_mixed, part);
+               g_object_unref (part);
+
+               attach_ids = e_ews_item_get_attachments_ids (item);
+               if (e_ews_connection_get_attachments_sync (cnc, EWS_PRIORITY_MEDIUM, NULL, attach_ids, NULL, 
FALSE, &attachments,
+                   NULL, NULL, cancellable, error)) {
+                       for (link = attachments; link; link = g_slist_next (link)) {
+                               EEwsAttachmentInfo *ainfo = link->data;
+
+                               if (ainfo && e_ews_attachment_info_get_type (ainfo) == 
E_EWS_ATTACHMENT_INFO_TYPE_INLINED) {
+                                       const gchar *mime_type;
+                                       const gchar *filename;
+                                       const gchar *content;
+                                       gsize content_len = 0;
+
+                                       mime_type = e_ews_attachment_info_get_mime_type (ainfo);
+                                       if (!mime_type)
+                                               mime_type = "application/octet-stream";
+
+                                       filename = e_ews_attachment_info_get_prefer_filename (ainfo);
+                                       if (!filename)
+                                               filename = e_ews_attachment_info_get_filename (ainfo);
+
+                                       content = e_ews_attachment_info_get_inlined_data (ainfo, 
&content_len);
+                                       if (!content) {
+                                               content = " ";
+                                               content_len = 1;
+                                       }
+
+                                       part = camel_mime_part_new ();
+                                       camel_mime_part_set_disposition (part, "attachment");
+                                       camel_mime_part_set_encoding (part, CAMEL_TRANSFER_ENCODING_BASE64);
+                                       camel_mime_part_set_content (part, content, content_len, mime_type);
+
+                                       if (filename)
+                                               camel_mime_part_set_filename (part, filename);
+
+                                       camel_multipart_add_part (m_mixed, part);
+                                       g_object_unref (part);
+                               }
+                       }
+
+                       g_slist_free_full (attachments, (GDestroyNotify) e_ews_attachment_info_free);
+               }
+
+               camel_medium_set_content (CAMEL_MEDIUM (msg), CAMEL_DATA_WRAPPER (m_mixed));
+
+               g_object_unref (m_mixed);
+       } else {
+               const gchar *body = e_ews_item_get_body (item);
+
+               if (!body || !*body)
+                       body = " ";
+
+               camel_mime_part_set_encoding (CAMEL_MIME_PART (msg), CAMEL_TRANSFER_ENCODING_8BIT);
+               camel_mime_part_set_content (CAMEL_MIME_PART (msg), body, strlen (body), "text/plain");
+       }
+
+       mime_fname_new = g_build_filename (mime_dir, "XXXXXX", NULL);
+       fd = g_mkstemp (mime_fname_new);
+       if (fd != -1)
+               e_ews_item_set_mime_content (item, mime_fname_new);
+       g_free (mime_fname_new);
+
+       if (fd == -1) {
+               g_set_error (
+                       error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+                       _("Unable to create cache file"));
+
+               g_slist_free_full (items, g_object_unref);
+               g_clear_object (&msg);
+               g_clear_object (&mi);
+
+               return FALSE;
+       }
+
+       new_stream = camel_stream_fs_new_with_fd (fd);
+       if (camel_data_wrapper_write_to_stream_sync (CAMEL_DATA_WRAPPER (msg), new_stream, cancellable, 
error) == -1 ||
+          camel_stream_flush (new_stream, cancellable, error) == -1 ||
+          camel_stream_close (new_stream, cancellable, error) == -1) {
+               g_slist_free_full (items, g_object_unref);
+               g_clear_object (&new_stream);
+               g_clear_object (&msg);
+               g_clear_object (&mi);
+
+               return FALSE;
+       }
+
+       g_clear_object (&new_stream);
+       g_clear_object (&msg);
+       g_clear_object (&mi);
+
+       *out_items = items;
+
+       return TRUE;
+}
+
 static CamelMimeMessage *
 camel_ews_folder_get_message (CamelFolder *folder,
                               const gchar *uid,
@@ -608,18 +801,46 @@ camel_ews_folder_get_message (CamelFolder *folder,
                (ESoapProgressFn) camel_operation_progress,
                (gpointer) cancellable,
                cancellable, &local_error);
-       g_free (mime_dir);
        e_ews_additional_props_free (add_props);
 
        if (!res || !items) {
                camel_ews_store_maybe_disconnect (ews_store, local_error);
                g_propagate_error (error, local_error);
+               g_free (mime_dir);
                goto exit;
        }
 
+       if (e_ews_item_get_item_type (items->data) == E_EWS_ITEM_TYPE_ERROR) {
+               if (g_error_matches (e_ews_item_get_error (items->data), EWS_CONNECTION_ERROR, 
EWS_CONNECTION_ERROR_MIMECONTENTCONVERSIONFAILED)) {
+                       g_slist_free_full (items, g_object_unref);
+                       items = NULL;
+                       /* The server failed to convert message into the MimeContent;
+                          construct it from the properties. */
+                       if (!ews_message_from_properties_sync (ews_folder, cnc, pri, ids, mime_dir, &items, 
cancellable, &local_error) || !items) {
+                               camel_ews_store_maybe_disconnect (ews_store, local_error);
+                               g_propagate_error (error, local_error);
+                               g_free (mime_dir);
+                               goto exit;
+                       }
+               }
+
+               if (e_ews_item_get_item_type (items->data) == E_EWS_ITEM_TYPE_ERROR) {
+                       local_error = g_error_copy (e_ews_item_get_error (items->data));
+                       camel_ews_store_maybe_disconnect (ews_store, local_error);
+                       if (local_error)
+                               g_propagate_error (error, local_error);
+                       g_free (mime_dir);
+                       goto exit;
+               }
+       }
+
+       g_free (mime_dir);
+
        /* The mime_content actually contains the *filename*, due to the
         * streaming hack in ESoapMessage */
        mime_content = e_ews_item_get_mime_content (items->data);
+       if (!mime_content)
+               goto exit;
 
        /* Exchange returns random UID for associated calendar item, which has no way
         * to match with calendar components saved in calendar cache. So manually get
diff --git a/src/camel/camel-ews-utils.c b/src/camel/camel-ews-utils.c
index f0f7a3f..ec76dd7 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -859,6 +859,116 @@ camel_ews_utils_sync_updated_items (CamelEwsFolder *ews_folder,
        g_slist_free (items_updated);
 }
 
+CamelMessageInfo * /* (transfer full) */
+camel_ews_utils_item_to_message_info (CamelEwsFolder *ews_folder,
+                                     EEwsConnection *cnc,
+                                     EEwsItem *item,
+                                     GCancellable *cancellable)
+{
+       CamelFolderSummary *folder_summary;
+       CamelMessageInfo *mi = NULL;
+       const EwsId *id;
+       const EwsMailbox *from;
+       gchar *tmp;
+       EEwsItemType item_type;
+       const gchar *msg_headers;
+       gboolean has_attachments, found_property, message_requests_read_receipt = FALSE;
+       guint32 server_flags;
+
+       g_return_val_if_fail (CAMEL_IS_EWS_FOLDER (ews_folder), NULL);
+
+       if (!item || e_ews_item_get_item_type (item) == E_EWS_ITEM_TYPE_ERROR)
+               return NULL;
+
+       id = e_ews_item_get_id (item);
+       if (!id)
+               return NULL;
+
+       folder_summary = camel_folder_get_folder_summary (CAMEL_FOLDER (ews_folder));
+
+       /* PidTagTransportMessageHeaders */
+       found_property = FALSE;
+       msg_headers = e_ews_item_get_extended_property_as_string (item, NULL, 0x007D, &found_property);
+       if (!found_property)
+               msg_headers = NULL;
+
+       if (msg_headers && *msg_headers) {
+               CamelMimePart *part = camel_mime_part_new ();
+               CamelStream *stream;
+               CamelMimeParser *parser;
+
+               stream = camel_stream_mem_new_with_buffer (msg_headers, strlen (msg_headers));
+               parser = camel_mime_parser_new ();
+               camel_mime_parser_init_with_stream (parser, stream, NULL);
+               camel_mime_parser_scan_from (parser, FALSE);
+               g_object_unref (stream);
+
+               if (camel_mime_part_construct_from_parser_sync (part, parser, NULL, NULL)) {
+                       mi = camel_folder_summary_info_new_from_headers (folder_summary, 
camel_medium_get_headers (CAMEL_MEDIUM (part)));
+                       if (camel_medium_get_header (CAMEL_MEDIUM (part), "Disposition-Notification-To"))
+                               message_requests_read_receipt = TRUE;
+               }
+
+               g_object_unref (parser);
+               g_object_unref (part);
+       }
+
+       if (!mi)
+               mi = camel_message_info_new (folder_summary);
+
+       camel_message_info_set_abort_notifications (mi, TRUE);
+
+       item_type = e_ews_item_get_item_type (item);
+       if (item_type == E_EWS_ITEM_TYPE_EVENT ||
+           item_type == E_EWS_ITEM_TYPE_MEETING_MESSAGE ||
+           item_type == E_EWS_ITEM_TYPE_MEETING_REQUEST ||
+           item_type == E_EWS_ITEM_TYPE_MEETING_RESPONSE ||
+           item_type == E_EWS_ITEM_TYPE_MEETING_RESPONSE)
+               camel_message_info_set_user_flag (mi, "$has_cal", TRUE);
+
+       camel_message_info_set_uid (mi, id->id);
+       camel_message_info_set_size (mi, e_ews_item_get_size (item));
+       camel_message_info_set_subject (mi, e_ews_item_get_subject (item));
+       camel_ews_message_info_set_item_type (CAMEL_EWS_MESSAGE_INFO (mi), item_type);
+       camel_ews_message_info_set_change_key (CAMEL_EWS_MESSAGE_INFO (mi), id->change_key);
+
+       camel_message_info_set_date_sent (mi, e_ews_item_get_date_sent (item));
+       camel_message_info_set_date_received (mi, e_ews_item_get_date_received (item));
+
+       from = e_ews_item_get_from (item);
+       if (!from)
+               from = e_ews_item_get_sender (item);
+       tmp = form_email_string_from_mb (cnc, from, cancellable);
+       camel_message_info_set_from (mi, tmp);
+       g_free (tmp);
+
+       tmp = form_recipient_list (cnc, e_ews_item_get_to_recipients (item), cancellable);
+       camel_message_info_set_to (mi, tmp);
+       g_free (tmp);
+
+       tmp = form_recipient_list (cnc, e_ews_item_get_cc_recipients (item), cancellable);
+       camel_message_info_set_cc (mi, tmp);
+       g_free (tmp);
+
+       e_ews_item_has_attachments (item, &has_attachments);
+       if (has_attachments)
+               camel_message_info_set_flags (mi, CAMEL_MESSAGE_ATTACHMENTS, CAMEL_MESSAGE_ATTACHMENTS);
+
+       ews_set_threading_data (mi, item);
+       server_flags = ews_utils_get_server_flags (item);
+       ews_utils_merge_server_user_flags (item, mi);
+
+       camel_message_info_set_flags (mi, server_flags, server_flags);
+       camel_ews_message_info_set_server_flags (CAMEL_EWS_MESSAGE_INFO (mi), server_flags);
+
+       camel_ews_utils_update_follow_up_flags (item, mi);
+       camel_ews_utils_update_read_receipt_flags (item, mi, server_flags, message_requests_read_receipt);
+
+       camel_message_info_set_abort_notifications (mi, FALSE);
+
+       return mi;
+}
+
 void
 camel_ews_utils_sync_created_items (CamelEwsFolder *ews_folder,
                                     EEwsConnection *cnc,
@@ -880,12 +990,6 @@ camel_ews_utils_sync_created_items (CamelEwsFolder *ews_folder,
                EEwsItem *item = (EEwsItem *) l->data;
                CamelMessageInfo *mi;
                const EwsId *id;
-               const EwsMailbox *from;
-               gchar *tmp;
-               EEwsItemType item_type;
-               const gchar *msg_headers;
-               gboolean has_attachments, found_property, message_requests_read_receipt = FALSE;
-               guint32 server_flags;
 
                if (!item)
                        continue;
@@ -910,87 +1014,13 @@ camel_ews_utils_sync_created_items (CamelEwsFolder *ews_folder,
                        continue;
                }
 
-
-               /* PidTagTransportMessageHeaders */
-               found_property = FALSE;
-               msg_headers = e_ews_item_get_extended_property_as_string (item, NULL, 0x007D, 
&found_property);
-               if (!found_property)
-                       msg_headers = NULL;
-
-               if (msg_headers && *msg_headers) {
-                       CamelMimePart *part = camel_mime_part_new ();
-                       CamelStream *stream;
-                       CamelMimeParser *parser;
-
-                       stream = camel_stream_mem_new_with_buffer (msg_headers, strlen (msg_headers));
-                       parser = camel_mime_parser_new ();
-                       camel_mime_parser_init_with_stream (parser, stream, NULL);
-                       camel_mime_parser_scan_from (parser, FALSE);
-                       g_object_unref (stream);
-
-                       if (camel_mime_part_construct_from_parser_sync (part, parser, NULL, NULL)) {
-                               mi = camel_folder_summary_info_new_from_headers (folder_summary, 
camel_medium_get_headers (CAMEL_MEDIUM (part)));
-                               if (camel_medium_get_header (CAMEL_MEDIUM (part), 
"Disposition-Notification-To"))
-                                       message_requests_read_receipt = TRUE;
-                       }
-
-                       g_object_unref (parser);
-                       g_object_unref (part);
+               mi = camel_ews_utils_item_to_message_info (ews_folder, cnc, item, cancellable);
+               if (!mi) {
+                       g_warn_if_reached ();
+                       g_object_unref (item);
+                       continue;
                }
 
-               if (!mi)
-                       mi = camel_message_info_new (folder_summary);
-
-               camel_message_info_set_abort_notifications (mi, TRUE);
-
-               item_type = e_ews_item_get_item_type (item);
-               if (item_type == E_EWS_ITEM_TYPE_EVENT ||
-                        item_type == E_EWS_ITEM_TYPE_MEETING_MESSAGE ||
-                        item_type == E_EWS_ITEM_TYPE_MEETING_REQUEST ||
-                        item_type == E_EWS_ITEM_TYPE_MEETING_RESPONSE ||
-                        item_type == E_EWS_ITEM_TYPE_MEETING_RESPONSE)
-                       camel_message_info_set_user_flag (mi, "$has_cal", TRUE);
-
-               camel_message_info_set_uid (mi, id->id);
-               camel_message_info_set_size (mi, e_ews_item_get_size (item));
-               camel_message_info_set_subject (mi, e_ews_item_get_subject (item));
-               camel_ews_message_info_set_item_type (CAMEL_EWS_MESSAGE_INFO (mi), item_type);
-               camel_ews_message_info_set_change_key (CAMEL_EWS_MESSAGE_INFO (mi), id->change_key);
-
-               camel_message_info_set_date_sent (mi, e_ews_item_get_date_sent (item));
-               camel_message_info_set_date_received (mi, e_ews_item_get_date_received (item));
-
-               from = e_ews_item_get_from (item);
-               if (!from)
-                       from = e_ews_item_get_sender (item);
-               tmp = form_email_string_from_mb (cnc, from, cancellable);
-               camel_message_info_set_from (mi, tmp);
-               g_free (tmp);
-
-               tmp = form_recipient_list (cnc, e_ews_item_get_to_recipients (item), cancellable);
-               camel_message_info_set_to (mi, tmp);
-               g_free (tmp);
-
-               tmp = form_recipient_list (cnc, e_ews_item_get_cc_recipients (item), cancellable);
-               camel_message_info_set_cc (mi, tmp);
-               g_free (tmp);
-
-               e_ews_item_has_attachments (item, &has_attachments);
-               if (has_attachments)
-                       camel_message_info_set_flags (mi, CAMEL_MESSAGE_ATTACHMENTS, 
CAMEL_MESSAGE_ATTACHMENTS);
-
-               ews_set_threading_data (mi, item);
-               server_flags = ews_utils_get_server_flags (item);
-               ews_utils_merge_server_user_flags (item, mi);
-
-               camel_message_info_set_flags (mi, server_flags, server_flags);
-               camel_ews_message_info_set_server_flags (CAMEL_EWS_MESSAGE_INFO (mi), server_flags);
-
-               camel_ews_utils_update_follow_up_flags (item, mi);
-               camel_ews_utils_update_read_receipt_flags (item, mi, server_flags, 
message_requests_read_receipt);
-
-               camel_message_info_set_abort_notifications (mi, FALSE);
-
                camel_folder_summary_add (folder_summary, mi, FALSE);
 
                /* camel_folder_summary_add() sets folder_flagged flag
diff --git a/src/camel/camel-ews-utils.h b/src/camel/camel-ews-utils.h
index 3a5a9c6..7234539 100644
--- a/src/camel/camel-ews-utils.h
+++ b/src/camel/camel-ews-utils.h
@@ -88,6 +88,12 @@ gboolean     camel_ews_utils_delete_folders_from_summary_recursive
 ESource *      camel_ews_utils_ref_corresponding_source
                                                (CamelService *service,
                                                 GCancellable *cancellable);
+CamelMessageInfo * /* (transfer full) */
+               camel_ews_utils_item_to_message_info
+                                               (CamelEwsFolder *ews_folder,
+                                                EEwsConnection *cnc,
+                                                EEwsItem *item,
+                                                GCancellable *cancellable);
 
 G_END_DECLS
 
diff --git a/src/server/e-ews-item.c b/src/server/e-ews-item.c
index 88c75a8..48684c2 100644
--- a/src/server/e-ews-item.c
+++ b/src/server/e-ews-item.c
@@ -108,6 +108,7 @@ struct _EEwsItemPrivate {
        EwsId *item_id;
        gchar *subject;
        gchar *mime_content;
+       gchar *body;
 
        gchar *date_header;
        time_t date_received;
@@ -201,43 +202,20 @@ e_ews_item_dispose (GObject *object)
                priv->attachment_id = NULL;
        }
 
-       g_free (priv->mime_content);
-
-       g_free (priv->subject);
-       priv->subject = NULL;
-
-       g_free (priv->msg_id);
-       priv->msg_id = NULL;
-
-       g_free (priv->uid);
-       priv->uid = NULL;
-
-       g_free (priv->in_replyto);
-       priv->in_replyto = NULL;
-
-       g_free (priv->references);
-       priv->references = NULL;
-
-       g_free (priv->date_header);
-       priv->date_header = NULL;
-
-       g_free (priv->timezone);
-       priv->timezone = NULL;
-
-       g_free (priv->start_timezone);
-       priv->start_timezone = NULL;
-
-       g_free (priv->end_timezone);
-       priv->end_timezone = NULL;
-
-       g_free (priv->contact_photo_id);
-       priv->contact_photo_id = NULL;
-
-       g_free (priv->iana_start_time_zone);
-       priv->iana_start_time_zone = NULL;
-
-       g_free (priv->iana_end_time_zone);
-       priv->iana_end_time_zone = NULL;
+       g_clear_pointer (&priv->mime_content, g_free);
+       g_clear_pointer (&priv->body, g_free);
+       g_clear_pointer (&priv->subject, g_free);
+       g_clear_pointer (&priv->msg_id, g_free);
+       g_clear_pointer (&priv->uid, g_free);
+       g_clear_pointer (&priv->in_replyto, g_free);
+       g_clear_pointer (&priv->references, g_free);
+       g_clear_pointer (&priv->date_header, g_free);
+       g_clear_pointer (&priv->timezone, g_free);
+       g_clear_pointer (&priv->start_timezone, g_free);
+       g_clear_pointer (&priv->end_timezone, g_free);
+       g_clear_pointer (&priv->contact_photo_id, g_free);
+       g_clear_pointer (&priv->iana_start_time_zone, g_free);
+       g_clear_pointer (&priv->iana_end_time_zone, g_free);
 
        g_slist_free_full (priv->to_recipients, (GDestroyNotify) e_ews_mailbox_free);
        priv->to_recipients = NULL;
@@ -254,8 +232,7 @@ e_ews_item_dispose (GObject *object)
        g_slist_free_full (priv->attachments_ids, g_free);
        priv->attachments_ids = NULL;
 
-       g_free (priv->my_response_type);
-       priv->my_response_type = NULL;
+       g_clear_pointer (&priv->my_response_type, g_free);
 
        g_slist_free_full (priv->attendees, (GDestroyNotify) ews_item_free_attendee);
        priv->attendees = NULL;
@@ -1666,8 +1643,9 @@ e_ews_item_set_from_soap_parameter (EEwsItem *item,
                        priv->start_timezone = e_soap_parameter_get_property (subparam, "Id");
                } else if (!g_ascii_strcasecmp (name, "EndTimeZone")) {
                        priv->end_timezone = e_soap_parameter_get_property (subparam, "Id");
+               } else if (!g_ascii_strcasecmp (name, "Body")) {
+                       priv->body = e_soap_parameter_get_string_value (subparam);
                }
-
        }
 
        return TRUE;
@@ -2310,6 +2288,7 @@ e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param,
        } else {
                info = e_ews_attachment_info_new (E_EWS_ATTACHMENT_INFO_TYPE_INLINED);
                e_ews_attachment_info_set_inlined_data (info, content, data_len);
+               e_ews_attachment_info_set_prefer_filename (info, name);
        }
        return info;
 }
@@ -2765,9 +2744,11 @@ const gchar *
 e_ews_item_get_body (EEwsItem *item)
 {
        g_return_val_if_fail (E_IS_EWS_ITEM (item), NULL);
-       g_return_val_if_fail (item->priv->task_fields != NULL, NULL);
 
-       return item->priv->task_fields->body;
+       if (item->priv->body)
+               return item->priv->body;
+
+       return item->priv->task_fields ? item->priv->task_fields->body : NULL;
 }
 
 const gchar *


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