[evolution-patches] Exchange patch for send options



Hi,

Saw that we are not handing send options while modifying the objects. Also, re-ordered the code.

Thanks
-- Sarfraaz
Index: calendar/e-cal-backend-exchange-calendar.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/calendar/e-cal-backend-exchange-calendar.c,v
retrieving revision 1.35
diff -u -p -u -r1.35 e-cal-backend-exchange-calendar.c
--- calendar/e-cal-backend-exchange-calendar.c	16 Feb 2005 07:58:48 -0000	1.35
+++ calendar/e-cal-backend-exchange-calendar.c	25 Feb 2005 13:24:30 -0000
@@ -55,6 +55,8 @@ static ECalBackendSyncStatus modify_obje
 
 static GSList * get_attachment (ECalBackendExchange *cbex, const char *uid, const char *body, int len);
 
+gboolean check_for_send_options (icalcomponent *icalcomp, E2kProperties *props);
+
 static void
 add_timezones_from_comp (ECalBackendExchange *cbex, icalcomponent *icalcomp)
 {
@@ -167,12 +169,13 @@ add_vevent (ECalBackendExchange *cbex,
 
 static gboolean
 add_ical (ECalBackendExchange *cbex, const char *href, const char *lastmod, 
-	  const char *uid, const char *body, int len)
+	  const char *uid, const char *body, int len, int receipts)
 {
 	const char *start, *end;
 	char *ical_body;
 	icalcomponent *icalcomp, *subcomp, *new_comp;
 	icalcomponent_kind kind;
+	icalproperty *icalprop;
 	ECalComponent *ecomp;
 	GSList *attachment_list = NULL;
 	gboolean status;
@@ -199,6 +202,11 @@ add_ical (ECalBackendExchange *cbex, con
 
 	kind = icalcomponent_isa (icalcomp);
 	if (kind == ICAL_VEVENT_COMPONENT) {
+		if (receipts) {
+			icalprop = icalproperty_new_x (g_strdup (receipts));
+			icalproperty_set_x_name (icalprop, "X-EVOLUTION-OPTIONS-TRACKINFO");
+			icalcomponent_add_property (icalcomp, icalprop);
+		}
 		if (attachment_list) {
 			ecomp = e_cal_component_new ();
 			e_cal_component_set_icalcomponent (ecomp, icalcomponent_new_clone (icalcomp));
@@ -314,12 +322,16 @@ static const char *event_properties[] = 
 	E2K_PR_CALENDAR_UID,
 	E2K_PR_DAV_LAST_MODIFIED,
 	E2K_PR_HTTPMAIL_HAS_ATTACHMENT,
+	PR_READ_RECEIPT_REQUESTED,
+	PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED	
 };
 static const int n_event_properties = G_N_ELEMENTS (event_properties);
 
 static const char *new_event_properties[] = {
 	PR_INTERNET_CONTENT,
 	E2K_PR_HTTPMAIL_HAS_ATTACHMENT,
+	PR_READ_RECEIPT_REQUESTED,
+	PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED	
 };
 static const int n_new_event_properties = G_N_ELEMENTS (new_event_properties);
 
@@ -332,11 +344,11 @@ get_changed_events (ECalBackendExchange 
 	E2kRestriction *rn;
 	E2kResultIter *iter;
 	E2kResult *result;
-	const char *prop, *uid, *modtime, *attach_prop;
+	const char *prop, *uid, *modtime, *attach_prop, *receipts;
 	char *body;
 	guint status;
 	E2kContext *ctx;
-	int i;
+	int i, status_tracking = 0;
 
 	g_return_val_if_fail (E_IS_CAL_BACKEND_EXCHANGE (cbex), SOUP_STATUS_CANCELLED);
 
@@ -388,6 +400,21 @@ get_changed_events (ECalBackendExchange 
 		attach_prop = e2k_properties_get_prop (result->props, 
 						E2K_PR_HTTPMAIL_HAS_ATTACHMENT);
 
+		receipts = e2k_properties_get_prop (result->props,
+						PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED);
+		if (receipts && atoi (receipts))
+			status_tracking = 1;
+	
+		receipts = NULL;
+		receipts = e2k_properties_get_prop (result->props,
+						PR_READ_RECEIPT_REQUESTED);
+		if (receipts && atoi (receipts)) {
+			if (status_tracking == 1)
+				status_tracking = 3;
+			else
+				status_tracking = 2;
+		}
+
 		if (!e_cal_backend_exchange_in_cache (cbex, uid, modtime, result->href)) {
 			g_ptr_array_add (hrefs, g_strdup (result->href));
 			g_hash_table_insert (modtimes, g_strdup (result->href),
@@ -430,6 +457,7 @@ get_changed_events (ECalBackendExchange 
 
 	while ((result = e2k_result_iter_next (iter))) {
 		GByteArray *ical_data;
+		status_tracking = 0;
 
 		ical_data = e2k_properties_get_prop (result->props, PR_INTERNET_CONTENT);
 		if (!ical_data) {
@@ -437,12 +465,27 @@ get_changed_events (ECalBackendExchange 
 			g_ptr_array_add (hrefs, g_strdup (result->href));
 			continue;
 		}
+		receipts = e2k_properties_get_prop (result->props,
+					PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED);
+		if (receipts && atoi (receipts))
+			status_tracking = 1;
+	
+		receipts = NULL;
+		receipts = e2k_properties_get_prop (result->props,
+					PR_READ_RECEIPT_REQUESTED);
+		if (receipts && atoi (receipts)) {
+			if (status_tracking == 1)
+				status_tracking = 3;
+			else
+				status_tracking = 2;
+		}
+
 		modtime = g_hash_table_lookup (modtimes, result->href);
 		uid = g_hash_table_lookup (attachments, result->href);
 		/* The icaldata already has the attachment. So no need to
 			re-fetch it from the server. */
 		add_ical (cbex, result->href, modtime, uid,
-			  ical_data->data, ical_data->len);
+			  ical_data->data, ical_data->len, status_tracking);
 	}
 	status = e2k_result_iter_free (iter);
 
@@ -474,7 +517,7 @@ get_changed_events (ECalBackendExchange 
 
 		uid = g_hash_table_lookup (attachments, hrefs->pdata[i]);
 
-		add_ical (cbex, hrefs->pdata[i], modtime, uid, body, length);
+		add_ical (cbex, hrefs->pdata[i], modtime, uid, body, length, 0);
 		g_free (body);
 	}
 
@@ -656,6 +699,48 @@ build_msg ( ECalBackendExchange *cbex, E
 	return buffer;
 }
 
+gboolean
+check_for_send_options (icalcomponent *icalcomp, E2kProperties *props)
+{
+	icalproperty *icalprop;
+	gboolean exists = FALSE;
+	const char *x_name, *x_val;
+
+	icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);	
+	while (icalprop) {
+		x_name = icalproperty_get_x_name (icalprop);
+		if (!strcmp(x_name, "X-EVOLUTION-OPTIONS-TRACKINFO")) {
+			exists = TRUE;
+			x_val = icalproperty_get_x (icalprop);
+			switch (atoi (x_val)) {
+				case 1: /* Track if delivered */
+					e2k_properties_set_int (props, 
+					PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED, 1);
+					printf ("Track if delivered \n");
+					break;
+				case 2: /* Track if opened */
+					printf ("Track if opened \n");
+					e2k_properties_set_int (props, 
+					PR_READ_RECEIPT_REQUESTED, 1);
+					break;
+				case 3: /* Track if delivered and opened */
+					printf ("Track if delivered and opened \n");
+					e2k_properties_set_int (props, 
+					PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED, 1);
+					e2k_properties_set_int (props, 
+					PR_READ_RECEIPT_REQUESTED, 1);
+					break;
+				default : /* None */
+					exists = FALSE;
+					break; 
+			}
+		}
+		icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
+	}
+
+	return exists;
+}
+
 static ECalBackendSyncStatus
 create_object (ECalBackendSync *backend, EDataCal *cal,
 	       char **calobj, char **uid)
@@ -678,7 +763,10 @@ create_object (ECalBackendSync *backend,
 	char *attach_body_crlf = NULL;
 	const char *boundary;
 	E2kHTTPStatus http_status;
+	E2kProperties *props = e2k_properties_new ();
+	E2kContext *e2kctx;
 	struct _cb_data *cbdata;
+	gboolean send_options;
 	
 	cbexc =	E_CAL_BACKEND_EXCHANGE_CALENDAR (backend);
 	
@@ -716,26 +804,8 @@ create_object (ECalBackendSync *backend,
 	#endif
 	
 	/* Send options */
-	icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);	
-	while (icalprop) {
-		x_name = icalproperty_get_x_name (icalprop);
-		if (!strcmp(x_name, "X-EVOLUTION-OPTIONS-TRACKINFO")) {
-			x_val = icalproperty_get_x (icalprop);
-			switch (atoi (x_val)) {
-				case 1: /* Track if delivered */
-					break;
-				case 2: /* Track if opened */
-					break;
-				case 3: /* Track if delivered and opened */
-					break;
-				default : /* None */
-					break; 
-			}
-		}
-		icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
-	}
-
-
+	send_options = check_for_send_options (icalcomp, props);
+	
 	/*set X-MICROSOFT-CDO properties*/
 	busystatus = "BUSY";
 	icalprop = icalcomponent_get_first_property (icalcomp, 
@@ -876,10 +946,19 @@ create_object (ECalBackendSync *backend,
 				       body_crlf);
 	}
 
+/*	status = e_folder_exchange_proppatch_new (E_CAL_BACKEND_EXCHANGE (cbexc)->folder, NULL,
+                                                  summary, NULL, NULL,
+                                                  props, &location, NULL );
+*/	
 	http_status = e_folder_exchange_put_new (E_CAL_BACKEND_EXCHANGE (cbexc)->folder, NULL, summary, 
 						NULL, NULL, "message/rfc822", 
 						msg, strlen(msg), &location, &ru_header);	
 
+	if ((http_status == E2K_HTTP_CREATED) && send_options) {
+		e2kctx = exchange_account_get_context (E_CAL_BACKEND_EXCHANGE (cbexc)->account);
+		http_status = e2k_context_proppatch (e2kctx, NULL, location, props, FALSE, NULL);
+	}
+
 	g_free (date);
 	g_free (from);
 	g_free (body_crlf);
@@ -900,6 +979,7 @@ create_object (ECalBackendSync *backend,
 	g_object_unref (comp);
 	g_free (lastmod);
 	g_free (location);
+	e2k_properties_free (props);
 	
 	return GNOME_Evolution_Calendar_Success;
 }
@@ -1033,9 +1113,11 @@ modify_object_with_href (ECalBackendSync
 	struct _cb_data *cbdata;
 	icalproperty *icalprop;
 	E2kHTTPStatus http_status;
-	char *from, *date;
+	char *from, *date, *location;
 	const char *summary, *new_href;
+	gboolean send_options;
 	E2kContext *ctx;
+	E2kProperties *props;
 
 	cbexc =	E_CAL_BACKEND_EXCHANGE_CALENDAR (backend);
 
@@ -1092,6 +1174,9 @@ modify_object_with_href (ECalBackendSync
 		icalproperty_remove_parameter (icalprop, ICAL_X_PARAMETER);
 	}
 
+	/* send options */
+	send_options = check_for_send_options (updated_icalcomp, props);
+
 	real_ecomp = e_cal_component_new ();
 	if (!e_cal_component_set_icalcomponent (real_ecomp, updated_icalcomp)) {
 		g_object_unref (real_ecomp);
@@ -1229,8 +1314,15 @@ modify_object_with_href (ECalBackendSync
 	else
 		new_href = ecomp->href;
 
+	/* status = e_folder_exchange_proppatch_new (ecalbex->folder, NULL,
+                                                  summary, NULL, NULL,
+                                                  props, new_href, NULL );
+	*/
 	http_status = e2k_context_put (ctx, NULL, new_href, "message/rfc822",
 				       		msg, strlen (msg), NULL);
+
+	if ((E2K_HTTP_STATUS_IS_SUCCESSFUL (http_status)) && send_options)
+		http_status = e2k_context_proppatch (ctx, NULL, new_href, props, FALSE, NULL);
 
 	if (E2K_HTTP_STATUS_IS_SUCCESSFUL (http_status))
 		e_cal_backend_exchange_modify_object (E_CAL_BACKEND_EXCHANGE (cbexc), 


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