[evolution-ews] Bug #660748 - Cann't save attachment in event



commit 0dfaeb4282fdb9658f975792e6b28bbe9594d621
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jul 29 12:58:53 2013 +0200

    Bug #660748 - Cann't save attachment in event

 src/calendar/e-cal-backend-ews.c |   47 ++++++++++++++++++++++++++++++++-----
 src/server/e-ews-connection.c    |   29 +++++++++++++++++++++--
 src/server/e-ews-item.h          |    8 +++++-
 3 files changed, 73 insertions(+), 11 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index 53913b4..84b2d6a 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -2409,23 +2409,38 @@ e_cal_backend_ews_modify_object (ECalBackend *backend,
                icalcomp = e_cal_component_get_icalcomponent (oldcomp);
                icalprop = icalcomponent_get_first_property (icalcomp, ICAL_ATTACH_PROPERTY);
                while (icalprop) {
-                       removed_attachments_ids = g_slist_append (removed_attachments_ids, 
icalproperty_get_parameter_as_string_r (icalprop, "X-EWS-ATTACHMENTID"));
+                       const gchar *attachment_url = icalproperty_get_value_as_string (icalprop);
+
+                       for (items = removed_attachments; items; items = items->next) {
+                               if (g_strcmp0 (attachment_url, items->data) == 0) {
+                                       break;
+                               }
+                       }
+
+                       /* not NULL means the attachment was found in removed attachments */
+                       if (items != NULL)
+                               removed_attachments_ids = g_slist_append (removed_attachments_ids, 
icalproperty_get_parameter_as_string_r (icalprop, "X-EWS-ATTACHMENTID"));
+
                        icalprop = icalcomponent_get_next_property (icalcomp, ICAL_ATTACH_PROPERTY);
                }
 
-               e_ews_connection_delete_attachments_sync (
-                       priv->cnc, EWS_PRIORITY_MEDIUM,
-                       removed_attachments_ids, &items, cancellable, &error);
+               items = NULL;
 
-               changekey = items->data;
+               if (removed_attachments_ids) {
+                       if (e_ews_connection_delete_attachments_sync (
+                               priv->cnc, EWS_PRIORITY_MEDIUM,
+                               removed_attachments_ids, &items, cancellable, &error) && items)
+                               changekey = items->data;
+               }
 
-               for (i = removed_attachments_ids; i; i = i->next) free (i->data);
-               g_slist_free (removed_attachments_ids);
+               g_slist_free_full (removed_attachments_ids, g_free);
                g_slist_free (removed_attachments);
        }
 
        /*in case we have a new attachmetns the update item will be preformed in ews_create_attachments_cb*/
        if (added_attachments) {
+               const gchar *old_uid = NULL;
+               gint old_uid_len = 0;
                GSList *info_attachments = NULL;
                EwsId *item_id = g_new0 (EwsId, 1);
                item_id->id = itemid;
@@ -2441,10 +2456,28 @@ e_cal_backend_ews_modify_object (ECalBackend *backend,
                attach_data->itemid = itemid;
                attach_data->changekey = changekey;
 
+               e_cal_component_get_uid (oldcomp, &old_uid);
+               if (old_uid)
+                       old_uid_len = strlen (old_uid);
+
                for (i = added_attachments; i; i = i->next) {
                        EEwsAttachmentInfo *info = e_ews_attachment_info_new (E_EWS_ATTACHMENT_INFO_TYPE_URI);
+
                        e_ews_attachment_info_set_uri (info, i->data);
 
+                       if (old_uid) {
+                               gchar *filename = g_filename_from_uri (i->data, NULL, NULL);
+                               if (filename) {
+                                       const gchar *slash = strrchr (filename, G_DIR_SEPARATOR);
+                                       if (slash && g_str_has_prefix (slash + 1, old_uid) &&
+                                           slash[1 + old_uid_len] == '-') {
+                                               e_ews_attachment_info_set_prefer_filename (info, slash + 1 + 
old_uid_len + 1);
+                                       }
+
+                                       g_free (filename);
+                               }
+                       }
+
                        info_attachments = g_slist_append (info_attachments, info);
                }
 
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 88e3d9c..9e9519d 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -1657,6 +1657,7 @@ e_ews_attachment_info_free (EEwsAttachmentInfo *info)
                break;
        }
 
+       g_free (info->prefer_filename);
        g_free (info);
 }
 
@@ -1667,6 +1668,27 @@ e_ews_attachment_info_get_type (EEwsAttachmentInfo *info)
 }
 
 const gchar *
+e_ews_attachment_info_get_prefer_filename (EEwsAttachmentInfo *info)
+{
+       g_return_val_if_fail (info != NULL, NULL);
+
+       return info->prefer_filename;
+}
+
+void
+e_ews_attachment_info_set_prefer_filename (EEwsAttachmentInfo *info,
+                                          const gchar *prefer_filename)
+{
+       g_return_if_fail (info != NULL);
+
+       if (info->prefer_filename == prefer_filename)
+               return;
+
+       g_free (info->prefer_filename);
+       info->prefer_filename = g_strdup (prefer_filename);
+}
+
+const gchar *
 e_ews_attachment_info_get_inlined_data (EEwsAttachmentInfo *info,
                                        gsize *len)
 {
@@ -6003,7 +6025,7 @@ e_ews_connection_attach_file (ESoapMessage *msg,
 {
        EEwsAttachmentInfoType type = e_ews_attachment_info_get_type (info);
        gchar *filename = NULL, *buffer = NULL;
-       const gchar *content = NULL;
+       const gchar *content = NULL, *prefer_filename;
        gsize length;
 
        switch (type) {
@@ -6024,7 +6046,7 @@ e_ews_connection_attach_file (ESoapMessage *msg,
                                return FALSE;
                        }
 
-                       g_file_get_contents (uri, &buffer, &length, &local_error);
+                       g_file_get_contents (filepath, &buffer, &length, &local_error);
                        if (local_error != NULL) {
                                g_free (filepath);
                                g_propagate_error (error, local_error);
@@ -6050,7 +6072,8 @@ e_ews_connection_attach_file (ESoapMessage *msg,
 
        e_soap_message_start_element (msg, "FileAttachment", NULL, NULL);
 
-       e_ews_message_write_string_parameter (msg, "Name", NULL, filename);
+       prefer_filename = e_ews_attachment_info_get_prefer_filename (info);
+       e_ews_message_write_string_parameter (msg, "Name", NULL, prefer_filename ? prefer_filename : 
filename);
        if (contact_photo)
                e_ews_message_write_string_parameter (msg, "IsContactPhoto", NULL, "true");
        e_soap_message_start_element (msg, "Content", NULL, NULL);
diff --git a/src/server/e-ews-item.h b/src/server/e-ews-item.h
index 8824d34..5a7309e 100644
--- a/src/server/e-ews-item.h
+++ b/src/server/e-ews-item.h
@@ -133,6 +133,7 @@ typedef struct {
                EEwsAttachmentInline inlined;
                gchar *uri;
        } data;
+       gchar *prefer_filename;
 } EEwsAttachmentInfo;
 
 typedef enum {
@@ -240,10 +241,15 @@ const EwsId *     e_ews_item_get_calendar_item_accept_id
                                                (EEwsItem *item);
 
 EEwsAttachmentInfo *
-               e_ews_attachment_info_new               (EEwsAttachmentInfoType type);
+               e_ews_attachment_info_new       (EEwsAttachmentInfoType type);
 void           e_ews_attachment_info_free      (EEwsAttachmentInfo *info);
 EEwsAttachmentInfoType
                e_ews_attachment_info_get_type  (EEwsAttachmentInfo *info);
+const gchar *  e_ews_attachment_info_get_prefer_filename
+                                               (EEwsAttachmentInfo *info);
+void           e_ews_attachment_info_set_prefer_filename
+                                               (EEwsAttachmentInfo *info,
+                                                const gchar *prefer_filename);
 const gchar *  e_ews_attachment_info_get_inlined_data
                                                (EEwsAttachmentInfo *info,
                                                 gsize *len);


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