Index: calendar/libedata-cal/e-cal-backend-util.c
===================================================================
--- calendar/libedata-cal/e-cal-backend-util.c	(revision 9075)
+++ calendar/libedata-cal/e-cal-backend-util.c	(working copy)
@@ -39,9 +39,13 @@ e_cal_backend_mail_account_get_default (
 {
 	const EAccount *account;
 
-	/* FIXME I think this leaks the gconf client */
-	if (accounts == NULL)
-		accounts = e_account_list_new(gconf_client_get_default());
+	if (accounts == NULL) {
+		GConfClient *gconf = gconf_client_get_default ();
+
+		accounts = e_account_list_new (gconf);
+
+		g_object_unref (gconf);
+	}
 
 	account = e_account_list_get_default(accounts);
 	if (account) {
@@ -66,9 +70,13 @@ e_cal_backend_mail_account_is_valid (cha
 {
 	const EAccount *account;
 
-	/* FIXME I think this leaks the gconf client */
-	if (accounts == NULL)
-		accounts = e_account_list_new(gconf_client_get_default());
+	if (accounts == NULL) {
+		GConfClient *gconf = gconf_client_get_default ();
+
+		accounts = e_account_list_new (gconf);
+
+		g_object_unref (gconf);
+	}
 
 	account = e_account_list_find(accounts, E_ACCOUNT_FIND_ID_ADDRESS, user);
 	if (account)
@@ -76,3 +84,90 @@ e_cal_backend_mail_account_is_valid (cha
 
 	return account != NULL;
 }
+
+/**
+ * is_attendee_declined:
+ * @param icalcomp Component where to check the attendee list.
+ * @param email Attendee's email to look for.
+ * @return Whether the required attendee declined or not.
+ *         It's not necessary to have this attendee in the list.
+ **/
+static gboolean
+is_attendee_declined (icalcomponent *icalcomp, const char *email)
+{
+	icalproperty *prop;
+	icalparameter *param;
+
+	g_return_val_if_fail (icalcomp != NULL, FALSE);
+	g_return_val_if_fail (email != NULL, FALSE);
+
+	for (prop = icalcomponent_get_first_property (icalcomp, ICAL_ATTENDEE_PROPERTY);
+	     prop != NULL;
+	     prop = icalcomponent_get_next_property (icalcomp, ICAL_ATTENDEE_PROPERTY)) {
+		const char *attendee;
+		char *text = NULL;
+
+		attendee = icalproperty_get_value_as_string (prop);
+		if (!attendee)
+			continue;
+
+		if (!g_ascii_strncasecmp (attendee, "mailto:", 7))
+			text = g_strdup (attendee + 7);
+		text = g_strstrip (text);
+
+		if (!g_ascii_strcasecmp (email, text)) {
+			g_free (text);
+			break;
+		}
+		g_free (text);
+	}
+
+	if (!prop)
+		return FALSE;
+
+	param = icalproperty_get_first_parameter (prop, ICAL_PARTSTAT_PARAMETER);
+
+	return param && icalparameter_get_partstat (param) == ICAL_PARTSTAT_DECLINED;
+}
+
+/**
+ * e_cal_backend_user_declined:
+ * @param icalcomp Component where to check.
+ * @return Whether icalcomp contains attendee with a mail same as any of configured
+ *         enabled mail account and whether this user declined.
+ **/
+gboolean
+e_cal_backend_user_declined (icalcomponent *icalcomp)
+{
+	gboolean res = FALSE;
+	EAccountList *accounts;
+	GConfClient *gconf;
+
+	g_return_val_if_fail (icalcomp != NULL, FALSE);
+
+	gconf = gconf_client_get_default ();
+	accounts = e_account_list_new (gconf);
+
+	if (accounts) {
+		EIterator *it;
+
+		for (it = e_list_get_iterator (E_LIST (accounts)); e_iterator_is_valid (it); e_iterator_next (it)) {
+			EAccount *account = (EAccount *) e_iterator_get (it);
+
+			if (account && account->enabled && e_account_get_string (account, E_ACCOUNT_ID_ADDRESS)) {
+				res = is_attendee_declined (icalcomp, e_account_get_string (account, E_ACCOUNT_ID_ADDRESS));
+
+				if (res)
+					break;
+			}
+		}
+
+		g_object_unref (it);
+		g_object_unref (accounts);
+	}
+
+	g_object_unref (gconf);
+
+	return res;
+}
+
Index: calendar/libedata-cal/e-cal-backend-util.h
===================================================================
--- calendar/libedata-cal/e-cal-backend-util.h	(revision 9075)
+++ calendar/libedata-cal/e-cal-backend-util.h	(working copy)
@@ -33,6 +33,8 @@ G_BEGIN_DECLS
 gboolean e_cal_backend_mail_account_get_default (char **address, char **name);
 gboolean e_cal_backend_mail_account_is_valid (char *user, char **name);
 
+gboolean e_cal_backend_user_declined (icalcomponent *icalcomp);
+
 G_END_DECLS
 
 #endif
Index: calendar/ChangeLog
===================================================================
--- calendar/ChangeLog	(revision 9075)
+++ calendar/ChangeLog	(working copy)
@@ -1,3 +1,21 @@
+2008-07-01  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #272932
+
+	* libedata-cal/e-cal-backend-util.c:
+	(e_cal_backend_mail_account_get_default),
+	(e_cal_backend_mail_account_is_valid): Do not leak GConfClient.
+	* libedata-cal/e-cal-backend-util.h: (e_cal_backend_user_declined):
+	* libedata-cal/e-cal-backend-util.c: (e_cal_backend_user_declined),
+	(is_attendee_declined): New helper function to check whether user
+	declined the meeting or not. It looks into all configured and enabled
+	mail accounts and checks with attendees in the icalcomponent.
+	* backends/file/e-cal-backend-file.c:
+	(e_cal_backend_file_receive_objects):
+	* backends/caldav/e-cal-backend-caldav.c: (process_object):
+	* backends/google/e-cal-backend-google.c: (receive_object):
+	Recognize declined objects and do not add them to the calendar.
+
 2008-06-25  Milan Crha  <mcrha@redhat.com>
 
 	** Fix for bug #476640
Index: calendar/backends/file/e-cal-backend-file.c
===================================================================
--- calendar/backends/file/e-cal-backend-file.c	(revision 9075)
+++ calendar/backends/file/e-cal-backend-file.c	(working copy)
@@ -2526,6 +2526,7 @@ e_cal_backend_file_receive_objects (ECal
 		const char *uid;
 		char *object, *old_object, *rid, *new_object;
 		ECalBackendFileObject *obj_data;
+		gboolean is_declined;
 
 		subcomp = l->data;
 
@@ -2550,8 +2551,10 @@ e_cal_backend_file_receive_objects (ECal
 		case ICAL_METHOD_PUBLISH:
 		case ICAL_METHOD_REQUEST:
 		case ICAL_METHOD_REPLY:
+			is_declined = e_cal_backend_user_declined (subcomp);
+
 			/* handle attachments */
-			if (e_cal_component_has_attachments (comp))
+			if (!is_declined && e_cal_component_has_attachments (comp))
 				fetch_attachments (backend, comp);
 			obj_data = g_hash_table_lookup (priv->comp_uid_hash, uid);
 			if (obj_data) {
@@ -2560,13 +2563,27 @@ e_cal_backend_file_receive_objects (ECal
 					remove_instance (cbfile, obj_data, rid);
 				else
 					remove_component (cbfile, uid, obj_data);
-				add_component (cbfile, comp, FALSE);
+
+				if (!is_declined)
+					add_component (cbfile, comp, FALSE);
 
 				object = e_cal_component_get_as_string (comp);
-				e_cal_backend_notify_object_modified (E_CAL_BACKEND (backend), old_object, object);
+				if (!is_declined)
+					e_cal_backend_notify_object_modified (E_CAL_BACKEND (backend), old_object, object);
+				else {
+					ECalComponentId *id = e_cal_component_get_id (comp);
+
+					if (rid)
+						e_cal_backend_notify_object_removed (E_CAL_BACKEND (backend), id, old_object, object);
+					else
+						e_cal_backend_notify_object_removed (E_CAL_BACKEND (backend), id, old_object, NULL);
+
+					e_cal_component_free_id (id);
+				}
+
 				g_free (object);
 				g_free (old_object);
-			} else {
+			} else if (!is_declined) {
 				add_component (cbfile, comp, FALSE);
 
 				object = e_cal_component_get_as_string (comp);
Index: calendar/backends/caldav/e-cal-backend-caldav.c
===================================================================
--- calendar/backends/caldav/e-cal-backend-caldav.c	(revision 9075)
+++ calendar/backends/caldav/e-cal-backend-caldav.c	(working copy)
@@ -1957,6 +1957,7 @@ process_object (ECalBackendCalDAV   *cbd
 	char                     *rid;
 	char                     *ostr;
 	char                     *oostr;
+	gboolean                  is_declined;
 
 	priv = E_CAL_BACKEND_CALDAV_GET_PRIVATE (cbdav);
 	backend = E_CAL_BACKEND (cbdav);
@@ -1987,6 +1988,7 @@ process_object (ECalBackendCalDAV   *cbd
 		case ICAL_METHOD_REQUEST:
 		case ICAL_METHOD_REPLY:
 
+		is_declined = e_cal_backend_user_declined (e_cal_component_get_icalcomponent (ecomp));
 		if (online) {
 			CalDAVObject object = { NULL, };
 
@@ -2000,20 +2002,30 @@ process_object (ECalBackendCalDAV   *cbd
 				object.href  = href;
 				object.etag  = etag;
 
-			} else {
+			} else if (!is_declined) {
 				object.href = e_cal_component_gen_href (ecomp);
 			}
 
-			object.cdata = pack_cobj (cbdav, ecomp);
-			status = caldav_server_put_object (cbdav, &object);
-			e_cal_component_set_etag (ecomp, object.etag);
-			caldav_object_free (&object, FALSE);
+			if (!is_declined || ccomp) {
+				if (!is_declined) {
+					object.cdata = pack_cobj (cbdav, ecomp);
+					status = caldav_server_put_object (cbdav, &object);
+				} else {
+					object.cdata = NULL;
+					status = caldav_server_delete_object (cbdav, &object);
+				}
+				e_cal_component_set_etag (ecomp, object.etag);
+				caldav_object_free (&object, FALSE);
+			}
 		} else {
-			ECalComponentSyncState sstate;
+			ECalComponentSyncState sstate = E_CAL_COMPONENT_IN_SYNCH;
 
 			if (ccomp) {
-				sstate = E_CAL_COMPONENT_LOCALLY_MODIFIED;
-			} else {
+				if (!is_declined)
+					sstate = E_CAL_COMPONENT_LOCALLY_MODIFIED;
+				else
+					sstate = E_CAL_COMPONENT_LOCALLY_DELETED;
+			} else if (!is_declined) {
 				sstate = E_CAL_COMPONENT_LOCALLY_CREATED;
 			}
 
@@ -2025,18 +2037,21 @@ process_object (ECalBackendCalDAV   *cbd
 			break;
 		}
 
-		e_cal_backend_cache_put_component (priv->cache, ecomp);
+		if (!is_declined)
+			e_cal_backend_cache_put_component (priv->cache, ecomp);
+		else
+			e_cal_backend_cache_remove_component (priv->cache, uid, rid);
 
 		if (ccomp) {
-
-			e_cal_backend_notify_object_modified (backend,
-							      ostr,
-							      oostr);
-
-		} else {
-
-			e_cal_backend_notify_object_created (backend,
-							     ostr);
+			if (!is_declined)
+				e_cal_backend_notify_object_modified (backend, ostr, oostr);
+			else {
+				id = e_cal_component_get_id (ccomp);
+				e_cal_backend_notify_object_removed (E_CAL_BACKEND (backend), id, oostr, NULL);
+				e_cal_component_free_id (id);
+			}
+		} else if (!is_declined) {
+			e_cal_backend_notify_object_created (backend, ostr);
 		}
 
 		break;
@@ -2084,11 +2099,11 @@ process_object (ECalBackendCalDAV   *cbd
 							      rid);
 
 			id = e_cal_component_get_id (ccomp);
-
 			e_cal_backend_notify_object_removed (E_CAL_BACKEND (backend),
 							     id,
 							     oostr,
 							     ostr);
+			e_cal_component_free_id (id);
 			break;
 
 		default:
Index: calendar/backends/google/e-cal-backend-google.c
===================================================================
--- calendar/backends/google/e-cal-backend-google.c	(revision 9075)
+++ calendar/backends/google/e-cal-backend-google.c	(working copy)
@@ -545,8 +545,7 @@ static receive_object (ECalBackendGoogle
 	GSList *comps = NULL, *l = NULL;
 	icalproperty_method method;
 	icalproperty *icalprop;
-	gboolean instances = TRUE, found = FALSE;
-	icalparameter_partstat pstatus = 0;
+	gboolean instances = TRUE, found = FALSE, is_declined;
 
 	priv = cbgo->priv;
 	icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);	
@@ -562,15 +561,17 @@ static receive_object (ECalBackendGoogle
 		}
 		icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
 	}
-	
+
+	is_declined = e_cal_backend_user_declined (icalcomp);
+
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (icalcomp));
 	method = icalcomponent_get_method (icalcomp);	
 
 	/* Attachments */
-	if (e_cal_component_has_attachments (comp)) 
+	if (!is_declined && e_cal_component_has_attachments (comp))
 		fetch_attachments (cbgo, comp);
-	 
+
 	/* Sent to Server */
 	item = e_go_item_from_cal_component (cbgo, comp);	
 	entry =	e_go_item_get_entry (item);
@@ -618,7 +619,7 @@ static receive_object (ECalBackendGoogle
 	for (l = comps; l != NULL; l = l->next) {
 		ECalComponent *component = E_CAL_COMPONENT (l->data);
 
-		if (pstatus == ICAL_PARTSTAT_DECLINED) {
+		if (is_declined) {
 			ECalComponentId *id = e_cal_component_get_id (component);
 
 			if (e_cal_backend_cache_remove_component (priv->cache, id->uid, id->rid)) {
