From b5f79aafe35ff69da0f1addf5194fdfd0ebc5498 Mon Sep 17 00:00:00 2001 From: mguessan Date: Wed, 18 Aug 2010 22:54:23 +0000 Subject: [PATCH] LDAP: avoid galLookup in iCal searches git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1366 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../exchange/dav/DavExchangeSession.java | 24 +++++++++++-------- src/java/davmail/ldap/LdapConnection.java | 5 +++- src/test/davmail/ldap/TestLdap.java | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 09213d34..0de29e1c 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -326,16 +326,14 @@ public class DavExchangeSession extends ExchangeSession { } protected boolean needGalLookup(String searchAttributeName, Set returningAttributes) { - // search attribute is gallookup attribute, need to fetch value for isMatch - if (GALLOOKUP_ATTRIBUTES.contains(searchAttributeName)) { + // return all attributes => call gallookup + if (returningAttributes == null || returningAttributes.isEmpty()) { return true; - } else if (returningAttributes == null) { - return true; - // iCal search, do not call gallookup + // iCal search, do not call gallookup } else if (returningAttributes.contains("apple-serviceslocator")) { return false; - // return all attributes => call gallookup - } else if (returningAttributes.isEmpty()) { + // search attribute is gallookup attribute, need to fetch value for isMatch + } else if (GALLOOKUP_ATTRIBUTES.contains(searchAttributeName)) { return true; } @@ -794,13 +792,19 @@ public class DavExchangeSession extends ExchangeSession { public boolean isMatch(ExchangeSession.Contact contact) { String lowerCaseValue = value.toLowerCase(); String actualValue = contact.get(attributeName); + Operator actualOperator = operator; + // patch for iCal search without galLookup + if (actualValue == null && ("givenName".equals(attributeName) || "sn".equals(attributeName))) { + actualValue = contact.get("cn"); + actualOperator = Operator.Like; + } if (actualValue == null) { return false; } actualValue = actualValue.toLowerCase(); - return (operator == Operator.IsEqualTo && actualValue.equals(lowerCaseValue)) || - (operator == Operator.Like && actualValue.contains(lowerCaseValue)) || - (operator == Operator.StartsWith && actualValue.startsWith(lowerCaseValue)); + return (actualOperator == Operator.IsEqualTo && actualValue.equals(lowerCaseValue)) || + (actualOperator == Operator.Like && actualValue.contains(lowerCaseValue)) || + (actualOperator == Operator.StartsWith && actualValue.startsWith(lowerCaseValue)); } } diff --git a/src/java/davmail/ldap/LdapConnection.java b/src/java/davmail/ldap/LdapConnection.java index 7502d54c..27b48200 100644 --- a/src/java/davmail/ldap/LdapConnection.java +++ b/src/java/davmail/ldap/LdapConnection.java @@ -228,8 +228,10 @@ public class LdapConnection extends AbstractConnection { LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("labeleduri", null); LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("apple-generateduid", null); - LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("apple-serviceslocator", null); LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("uidnumber", null); + + // iCal search attribute + LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("apple-serviceslocator", "apple-serviceslocator"); } /** @@ -1417,6 +1419,7 @@ public class LdapConnection extends AbstractConnection { Map results = new HashMap(); Set contactReturningAttributes = convertLdapToContactReturningAttributes(returningAttributes); + contactReturningAttributes.remove("apple-serviceslocator"); List contacts = session.searchContacts(ExchangeSession.CONTACTS, contactReturningAttributes, condition, maxCount); for (ExchangeSession.Contact contact : contacts) { diff --git a/src/test/davmail/ldap/TestLdap.java b/src/test/davmail/ldap/TestLdap.java index 820e39cd..a6327ff4 100644 --- a/src/test/davmail/ldap/TestLdap.java +++ b/src/test/davmail/ldap/TestLdap.java @@ -106,7 +106,7 @@ public class TestLdap extends AbstractExchangeSessionTestCase { assertTrue(searchResults.hasMore()); } - public void testAnotherOSXSearch() throws NamingException { + public void testOSXICalSearch() throws NamingException { SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE); searchControls.setReturningAttributes(new String[]{"uid", "mail", "sn", "cn", "description", "apple-generateduid", "givenname", "apple-serviceslocator", "uidnumber"});