[evolution-ews] Pass component uid to the attachment dumping function to include it in the path



commit a8c56b3393b430ea679f4b8d29806aac21e3f4f4
Author: Or Goshen <orx goshen intel com>
Date:   Mon Aug 1 12:22:28 2011 +0300

    Pass component uid to the attachment dumping function to include it in the path

 src/calendar/e-cal-backend-ews.c |   20 +++++++++-----------
 src/server/e-ews-connection.c    |    8 ++++++--
 src/server/e-ews-connection.h    |    2 ++
 src/server/e-ews-item.c          |   13 ++++++-------
 src/server/e-ews-item.h          |    2 +-
 5 files changed, 24 insertions(+), 21 deletions(-)
---
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index 9d707c5..6c145cc 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -1530,7 +1530,7 @@ ews_cal_modify_object_cb (GObject *object, GAsyncResult *res, gpointer user_data
 	icalproperty *icalprop;
 	icalcomponent *icalcomp;
 	ECalComponentId *id;
-	GSList *original_attachments = NULL, *modified_attachments = NULL, *added_attachments, *removed_attachments, *removed_attachments_ids = NULL, *i;
+	GSList *original_attachments = NULL, *modified_attachments = NULL, *added_attachments = NULL, *removed_attachments = NULL, *removed_attachments_ids = NULL, *i;
 	const gchar *x_name;
 	EwsAttachmentsData *attach_data;
 
@@ -1587,9 +1587,11 @@ ews_cal_modify_object_cb (GObject *object, GAsyncResult *res, gpointer user_data
 	e_cal_component_get_attachment_list (modify_data->oldcomp, &original_attachments);
 	e_cal_component_get_attachment_list (modify_data->comp, &modified_attachments);
 
-	ewscal_get_attach_differences (original_attachments, modified_attachments, &removed_attachments, &added_attachments);
+	/*ewscal_get_attach_differences (original_attachments, modified_attachments, &removed_attachments, &added_attachments);
 	g_slist_free (original_attachments);
-	g_slist_free (modified_attachments);
+	g_slist_free (modified_attachments);*/
+	removed_attachments = original_attachments;
+	added_attachments = modified_attachments;
 
 	if (added_attachments) {
 		attach_data = g_new0(EwsAttachmentsData, 1);
@@ -1607,14 +1609,7 @@ ews_cal_modify_object_cb (GObject *object, GAsyncResult *res, gpointer user_data
 		/* convert attachment uri to attachment id, should have used a hash table somehow */
 		icalprop = icalcomponent_get_first_property (icalcomp, ICAL_ATTACH_PROPERTY);
 		while (icalprop) {
-			x_name = icalproperty_get_value_as_string (icalprop);
-
-			for (i = removed_attachments; i; i = i->next)
-				if (g_strcmp0 (i->data, x_name)) {
-					removed_attachments_ids = g_slist_append (removed_attachments_ids, icalproperty_get_parameter_as_string_r (icalprop, "X-EWS-ATTACHMENTID"));
-					break;
-				}
-
+			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);
 		}
 
@@ -2514,6 +2509,7 @@ ews_get_attachments (ECalBackendEws *cbews, EEwsItem *item)
 		const GSList *attachment_ids;
 		const EwsId *item_id;
 		EwsAttachmentData *att_data;
+		const gchar *uid;
 
 		attachment_ids = e_ews_item_get_attachments_ids (item);
 		item_id = e_ews_item_get_id (item);
@@ -2521,9 +2517,11 @@ ews_get_attachments (ECalBackendEws *cbews, EEwsItem *item)
 		att_data->comp = g_hash_table_lookup (cbews->priv->item_id_hash, item_id->id);
 		att_data->cbews = cbews;
 		att_data->itemid = g_strdup (item_id->id);
+		e_cal_component_get_uid (att_data->comp, &uid);
 
 		e_ews_connection_get_attachments_start (cbews->priv->cnc,
 							EWS_PRIORITY_MEDIUM,
+							uid,
 							attachment_ids,
 							e_cal_backend_get_cache_dir(E_CAL_BACKEND(cbews)),
 							TRUE,
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index abfb37b..9e1768b 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -3697,6 +3697,7 @@ static void get_attachments_response_cb (ESoapParameter *subparam, EwsNode *enod
 void
 e_ews_connection_get_attachments_start	(EEwsConnection *cnc,
 					 gint pri,
+					 const gchar *uid,
 					 const GSList *ids,
 					 const gchar *cache,
 					 gboolean include_mime,
@@ -3742,6 +3743,7 @@ e_ews_connection_get_attachments_start	(EEwsConnection *cnc,
 
 	async_data = g_new0 (EwsAsyncData, 1);
 	async_data->directory = cache;
+	async_data->sync_state = (gchar *)uid;
 	g_simple_async_result_set_op_res_gpointer (
 		simple, async_data, (GDestroyNotify) async_data_free);
 
@@ -3777,6 +3779,7 @@ e_ews_connection_get_attachments_finish(EEwsConnection *cnc,
 GSList *
 e_ews_connection_get_attachments(EEwsConnection *cnc,
 				 gint pri,
+				 const gchar *uid,
 				 GSList *ids,
 				 const gchar *cache,
 				 gboolean include_mime,
@@ -3792,7 +3795,7 @@ e_ews_connection_get_attachments(EEwsConnection *cnc,
 	sync_data = g_new0 (EwsSyncData, 1);
 	sync_data->eflag = e_flag_new ();
 
-	e_ews_connection_get_attachments_start	(cnc,pri,ids,cache,include_mime,
+	e_ews_connection_get_attachments_start	(cnc,pri,uid,ids,cache,include_mime,
 						 ews_sync_reply_cb,
 						 progress_fn, progress_data,
 						 cancellable,
@@ -3835,7 +3838,8 @@ get_attachments_response_cb (ESoapParameter *param, EwsNode *enode)
 
 		}
 		else if (!g_ascii_strcasecmp (name, "FileAttachment")) {
-			uri = e_ews_dump_file_attachment_from_soap_parameter(subparam, async_data->directory, &attach_id);
+			uri = e_ews_dump_file_attachment_from_soap_parameter(subparam, async_data->directory, async_data->sync_state, &attach_id);
+			g_warning ("DDD uid:%s -> attach_id:%s + uri:%s\n", async_data->sync_state, attach_id, uri);
 		}
 		if (uri && attach_id) {
 			async_data->items = g_slist_append (async_data->items, uri);
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index 41d5b52..ec3140d 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -552,6 +552,7 @@ GSList *	e_ews_connection_delete_attachments
 void		e_ews_connection_get_attachments_start
 						(EEwsConnection *cnc,
 						 gint pri,
+						 const gchar *comp_uid,
 						 const GSList *ids,
 						 const gchar *cache,
 						 gboolean include_mime,
@@ -570,6 +571,7 @@ GSList *	e_ews_connection_get_attachments_finish
 GSList *	e_ews_connection_get_attachments
 						(EEwsConnection *cnc,
 						 gint pri,
+						 const gchar *comp_uid,
 						 GSList *ids,
 						 const gchar *cache,
 						 gboolean include_mime,
diff --git a/src/server/e-ews-item.c b/src/server/e-ews-item.c
index a982fdb..5b1c4f6 100644
--- a/src/server/e-ews-item.c
+++ b/src/server/e-ews-item.c
@@ -1339,7 +1339,7 @@ e_ews_embed_attachment_id_in_uri (const gchar *olduri, const char *attach_id)
 }
 
 gchar *
-e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param, const gchar *cache, gchar **attach_id)
+e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param, const gchar *cache, const gchar *comp_uid, gchar **attach_id)
 {
 	ESoapParameter *subparam;
 	const gchar *param_name;
@@ -1364,9 +1364,7 @@ e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param, const gch
 			content = g_base64_decode (value, &data_len);
 			g_free (value);
 		} else if (g_ascii_strcasecmp(param_name, "AttachmentId") == 0) {
-			value = e_soap_parameter_get_property (subparam, "Id");
-			*attach_id = g_uri_escape_string(value, "", TRUE);
-			g_free (value);
+			*attach_id = e_soap_parameter_get_property (subparam, "Id");
 		}
 	}
 
@@ -1381,7 +1379,7 @@ e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param, const gch
 	tmpfilename = (gchar *) content;
 	tmpdir = g_strndup(tmpfilename, g_strrstr (tmpfilename, "/") - tmpfilename);
 
-	dirname = g_build_filename (tmpdir, *attach_id, NULL);
+	dirname = g_build_filename (tmpdir, comp_uid, NULL);
 	if (g_mkdir_with_parents (dirname, 0775) == -1) {
 		g_warning("Failed create directory to place file in [%s]: %s\n", dirname, strerror (errno));
 	}
@@ -1392,13 +1390,14 @@ e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param, const gch
 	}
 
 	g_free (dirname);
-	g_free (filename);
 	g_free(tmpdir);
 	g_free(name);
 	g_free(content);
 
 	/* Return URI to saved file */
-	return g_filename_to_uri(filename, NULL, NULL);
+	name = g_filename_to_uri(filename, NULL, NULL);
+	g_free (filename);
+	return name;
 }
 
 gchar *
diff --git a/src/server/e-ews-item.h b/src/server/e-ews-item.h
index de6d332..e81f159 100644
--- a/src/server/e-ews-item.h
+++ b/src/server/e-ews-item.h
@@ -157,7 +157,7 @@ gchar *		e_ews_embed_attachment_id_in_uri (const gchar *olduri, const char *atta
 GSList *	e_ews_item_get_attachments_ids
 						(EEwsItem *item);
 gchar *
-e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param, const gchar *cache, gchar **attach_id);
+e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param, const gchar *cache, const gchar *comp_uid, gchar **attach_id);
 
 gchar *
 e_ews_item_ical_dump(EEwsItem *item);



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