[evolution-exchange] Bug #521956 - Groups from Global Address List are incomplete



commit 7bef2ea13d73c8d5832b752b1e8796281eeadd90
Author: Milan Crha <mcrha redhat com>
Date:   Thu Oct 15 14:49:37 2009 +0200

    Bug #521956 - Groups from Global Address List are incomplete

 addressbook/e-book-backend-gal.c  |   47 +++++++++++++++++++++++-------------
 camel/camel-exchange-provider.c   |    2 +
 server/storage/exchange-esource.c |   13 ++++++++++
 3 files changed, 45 insertions(+), 17 deletions(-)
---
diff --git a/addressbook/e-book-backend-gal.c b/addressbook/e-book-backend-gal.c
index 03ac4d3..084970d 100644
--- a/addressbook/e-book-backend-gal.c
+++ b/addressbook/e-book-backend-gal.c
@@ -227,6 +227,15 @@ can_browse (EBookBackend *backend)
 		strcmp (e_source_get_property (e_book_backend_get_source (backend), "can-browse"), "1") == 0;
 }
 
+static gboolean
+can_expand_groups (EBookBackend *backend)
+{
+	return backend &&
+		e_book_backend_get_source (backend) &&
+		e_source_get_property (e_book_backend_get_source (backend), "expand-groups") &&
+		strcmp (e_source_get_property (e_book_backend_get_source (backend), "expand-groups"), "1") == 0;
+}
+
 static void
 book_view_notify_status (EDataBookView *view, const gchar *status)
 {
@@ -1061,10 +1070,10 @@ func_contains(ESExp *f, gint argc, ESExpResult **argv, gpointer data)
 		r->value.string = g_strdup_printf ("(%s=*)", ldap_attr);
 	} else if (!strcmp(propname, "file_as")) {
 		r = e_sexp_result_new(f, ESEXP_RES_STRING);
-		r->value.string = g_strdup_printf ("(|(displayName=%s*)(sn=%s*)(%s=%s*))", str, str, ldap_attr, str);
+		r->value.string = g_strdup_printf ("(|(displayName=*%s*)(sn=*%s*)(%s=*%s*))", str, str, ldap_attr, str);
 	} else if (g_str_equal (ldap_attr, "displayName")) {
 		r = e_sexp_result_new(f, ESEXP_RES_STRING);
-		r->value.string = g_strdup_printf("(|(displayName=%s*)(sn=%s*)(givenName=%s*))", str, str, str);
+		r->value.string = g_strdup_printf("(|(displayName=*%s*)(sn=*%s*)(givenName=*%s*))", str, str, str);
 	} else
 		r = e_sexp_result_new(f, ESEXP_RES_UNDEFINED);
 	return r;
@@ -1382,7 +1391,7 @@ build_contact_from_entry (EBookBackendGAL *bl, LDAPMessage *e, GList **existing_
 	EContact *contact = e_contact_new ();
 	gchar *dn;
 	gchar *attr;
-	BerElement *ber = NULL, *tber = NULL;
+	BerElement *ber = NULL;
 	gboolean is_group = FALSE;
 
 	g_mutex_lock (bl->priv->ldap_lock);
@@ -1392,21 +1401,25 @@ build_contact_from_entry (EBookBackendGAL *bl, LDAPMessage *e, GList **existing_
 	e_contact_set (contact, E_CONTACT_UID, dn);
 	ldap_memfree (dn);
 
-	g_mutex_lock (bl->priv->ldap_lock);
-	attr = ldap_first_attribute (bl->priv->ldap, e, &tber);
-	while (attr) {
-		if (!strcmp(attr, "member")) {
-			d(printf("It is a DL\n"));
-			is_group = TRUE;
+	if (can_expand_groups (E_BOOK_BACKEND (bl))) {
+		BerElement *tber = NULL;
+
+		g_mutex_lock (bl->priv->ldap_lock);
+		attr = ldap_first_attribute (bl->priv->ldap, e, &tber);
+		while (attr) {
+			if (!strcmp(attr, "member")) {
+				d(printf("It is a DL\n"));
+				is_group = TRUE;
+				ldap_memfree (attr);
+				break;
+			}
 			ldap_memfree (attr);
-			break;
+			attr = ldap_next_attribute (bl->priv->ldap, e, tber);
 		}
-		ldap_memfree (attr);
-		attr = ldap_next_attribute (bl->priv->ldap, e, tber);
+		if (tber)
+			ber_free (tber, 0);
+		g_mutex_unlock (bl->priv->ldap_lock);
 	}
-	if (tber)
-		ber_free (tber, 0);
-	g_mutex_unlock (bl->priv->ldap_lock);
 
 	g_mutex_lock (bl->priv->ldap_lock);
 	attr = ldap_first_attribute (bl->priv->ldap, e, &ber);
@@ -1460,7 +1473,7 @@ build_contact_from_entry (EBookBackendGAL *bl, LDAPMessage *e, GList **existing_
 							   which calls g_object_set to set the property */
 							info->populate_contact_func(contact, values, bl, NULL);
 						}
-						else if (info->prop_type & PROP_TYPE_GROUP) {
+						else if (is_group && (info->prop_type & PROP_TYPE_GROUP)) {
 							gchar *grpattrs[3];
 							gint i, view_limit = -1, ldap_error = LDAP_SUCCESS, count;
 							EDataBookView *book_view;
@@ -1493,7 +1506,7 @@ build_contact_from_entry (EBookBackendGAL *bl, LDAPMessage *e, GList **existing_
 									if (subldap && (ldap_error = ldap_search_ext_s (subldap,
 												values[i],
 												LDAP_SCOPE_BASE,
-												"(objectclass=User)",
+												"(objectclass=*)",
 												grpattrs, 0,
 												NULL,
 												NULL,
diff --git a/camel/camel-exchange-provider.c b/camel/camel-exchange-provider.c
index 2b3f6e0..f8cb314 100644
--- a/camel/camel-exchange-provider.c
+++ b/camel/camel-exchange-provider.c
@@ -86,6 +86,8 @@ CamelProviderConfEntry exchange_conf_entries[] = {
 	  N_("Authentication _Type:"), "default:Secure or Plaintext Password:basic:Plaintext Password:ntlm:Secure Password" },
 	{ CAMEL_PROVIDER_CONF_CHECKBOX, "ad_browse", NULL,
 	  N_("Allow _browsing of the GAL until download limit is reached"), "0" },
+	{ CAMEL_PROVIDER_CONF_CHECKBOX, "ad_expand_groups", NULL,
+	  N_("_Expand groups of contacts in GAL to contact lists"), "0" },
 	{ CAMEL_PROVIDER_CONF_SECTION_END },
 	{ CAMEL_PROVIDER_CONF_SECTION_START, "generals", NULL,
 	  N_("Options") },
diff --git a/server/storage/exchange-esource.c b/server/storage/exchange-esource.c
index 009656d..167b293 100644
--- a/server/storage/exchange-esource.c
+++ b/server/storage/exchange-esource.c
@@ -143,11 +143,14 @@ add_folder_esource (ExchangeAccount *account,
 
 		if (is_contacts_folder && g_str_has_prefix (physical_uri, "gal://")) {
 			gchar *browse = exchange_account_get_account_uri_param (account, "ad_browse");
+			gchar *expand_groups = exchange_account_get_account_uri_param (account, "ad_expand_groups");
 
 			source = e_source_new_with_absolute_uri (folder_name,
 								 physical_uri);
 			e_source_set_property (source, "completion", "true");
 			e_source_set_property (source, "can-browse", browse ? "1" : NULL);
+			e_source_set_property (source, "expand-groups", expand_groups ? "1" : NULL);
+			g_free (expand_groups);
 			g_free (browse);
 		}
 		else {
@@ -185,11 +188,14 @@ add_folder_esource (ExchangeAccount *account,
 							folder_name)) == NULL) {
 			if (is_contacts_folder && g_str_has_prefix (physical_uri, "gal://")) {
 				gchar *browse = exchange_account_get_account_uri_param (account, "ad_browse");
+				gchar *expand_groups = exchange_account_get_account_uri_param (account, "ad_expand_groups");
 
 				source = e_source_new_with_absolute_uri (
 						folder_name, physical_uri);
 				e_source_set_property (source, "completion", "true");
 				e_source_set_property (source, "can-browse", browse ? "1" : NULL);
+				e_source_set_property (source, "expand-groups", expand_groups ? "1" : NULL);
+				g_free (expand_groups);
 				g_free (browse);
 			}
 			else {
@@ -232,11 +238,18 @@ add_folder_esource (ExchangeAccount *account,
 			if (is_contacts_folder && g_str_has_prefix (physical_uri, "gal://")) {
 				gchar *browse = exchange_account_get_account_uri_param (account, "ad_browse");
 				const gchar *old_browse = e_source_get_property (source, "can-browse");
+				gchar *expand_groups = exchange_account_get_account_uri_param (account, "ad_expand_groups");
+				const gchar *old_expand_groups = e_source_get_property (source, "expand-groups");
 
 				if ((old_browse || browse) && (!old_browse || !browse)) {
 					e_source_set_property (source, "can-browse", browse ? "1" : NULL);
 				}
 
+				if ((old_expand_groups || expand_groups) && (!old_expand_groups || !expand_groups)) {
+					e_source_set_property (source, "expand-groups", expand_groups ? "1" : NULL);
+				}
+
+				g_free (expand_groups);
 				g_free (browse);
 			}
 		}



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