LDAP: avoid galLookup in iCal searches

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1366 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-08-18 22:54:23 +00:00
parent 77f05c88f3
commit b5f79aafe3
3 changed files with 19 additions and 12 deletions

View File

@ -326,16 +326,14 @@ public class DavExchangeSession extends ExchangeSession {
}
protected boolean needGalLookup(String searchAttributeName, Set<String> 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));
}
}

View File

@ -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<String, ExchangeSession.Contact> results = new HashMap<String, ExchangeSession.Contact>();
Set<String> contactReturningAttributes = convertLdapToContactReturningAttributes(returningAttributes);
contactReturningAttributes.remove("apple-serviceslocator");
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, contactReturningAttributes, condition, maxCount);
for (ExchangeSession.Contact contact : contacts) {

View File

@ -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"});