[evolution-ews/gnome-3-8] Bug #660748 - Can't save attachment in event
- From: Fabiano Fidêncio <ffidencio src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews/gnome-3-8] Bug #660748 - Can't save attachment in event
- Date: Mon, 5 Aug 2013 08:58:15 +0000 (UTC)
commit 69a65e4c77e65f70736b100b6c6337818ce41082
Author: Milan Crha <mcrha redhat com>
Date: Mon Jul 29 12:58:53 2013 +0200
Bug #660748 - Can't save attachment in event
src/calendar/e-cal-backend-ews.c | 47 ++++++++++++++++++++++++++++++++-----
src/server/e-ews-connection.c | 31 +++++++++++++++++++++---
src/server/e-ews-connection.h | 1 +
src/server/e-ews-item.h | 8 +++++-
4 files changed, 75 insertions(+), 12 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index cffa29e..36d5ff6 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -2452,23 +2452,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);
}
- items = e_ews_connection_delete_attachments_sync (
- priv->cnc, EWS_PRIORITY_MEDIUM,
- removed_attachments_ids, 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;
@@ -2484,10 +2499,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 e8faf0b..a484f84 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -1603,6 +1603,7 @@ e_ews_attachment_info_free (EEwsAttachmentInfo *info)
break;
}
+ g_free (info->prefer_filename);
g_free (info);
}
@@ -1613,6 +1614,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)
{
@@ -5703,7 +5725,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) {
@@ -5724,7 +5746,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);
@@ -5750,8 +5772,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);
e_soap_message_start_element (msg, "Content", NULL, NULL);
e_soap_message_write_base64 (msg, content, length);
e_soap_message_end_element (msg); /* "Content" */
@@ -6013,6 +6035,7 @@ GSList *
e_ews_connection_delete_attachments_sync (EEwsConnection *cnc,
gint pri,
const GSList *ids,
+ GSList **parents_ids,
GCancellable *cancellable,
GError **error)
{
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index 3c368d5..02e8763 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -707,6 +707,7 @@ GSList * e_ews_connection_delete_attachments_sync
(EEwsConnection *cnc,
gint pri,
const GSList *ids,
+ GSList **parents_ids,
GCancellable *cancellable,
GError **error);
diff --git a/src/server/e-ews-item.h b/src/server/e-ews-item.h
index 220c517..5dbf82c 100644
--- a/src/server/e-ews-item.h
+++ b/src/server/e-ews-item.h
@@ -132,6 +132,7 @@ typedef struct {
EEwsAttachmentInline inlined;
gchar *uri;
} data;
+ gchar *prefer_filename;
} EEwsAttachmentInfo;
typedef enum {
@@ -238,10 +239,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]