From 39079d371923845002133f40a3d7dc19dc32c690 Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 6 Sep 2010 22:55:29 +0000 Subject: [PATCH] LDAP: improve EWS filter support git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1426 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ews/EwsExchangeSession.java | 16 +++++++++++++--- src/java/davmail/ldap/LdapConnection.java | 5 ++--- src/test/davmail/ldap/TestLdap.java | 8 ++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index 7a5411b6..4dac66a1 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -149,7 +149,7 @@ public class EwsExchangeSession extends ExchangeSession { protected static class AutoDiscoverMethod extends PostMethod { AutoDiscoverMethod(String autodiscoverHost, String userEmail) { - super("https://"+autodiscoverHost+"/autodiscover/autodiscover.xml"); + super("https://" + autodiscoverHost + "/autodiscover/autodiscover.xml"); setAutoDiscoverRequestEntity(userEmail); } @@ -529,6 +529,16 @@ public class EwsExchangeSession extends ExchangeSession { // encode urlcompname if (fieldURI instanceof ExtendedFieldURI && "0x10f3".equals(((ExtendedFieldURI) fieldURI).propertyTag)) { buffer.append(StringUtil.xmlEncode(StringUtil.encodeUrlcompname(value))); + } else if (fieldURI instanceof ExtendedFieldURI + && ((ExtendedFieldURI) fieldURI).propertyType == ExtendedFieldURI.PropertyType.Integer) { + // check value + try { + Integer.parseInt(value); + buffer.append(value); + } catch (NumberFormatException e) { + // invalid value, replace with 0 + buffer.append('0'); + } } else { buffer.append(StringUtil.xmlEncode(value)); } @@ -1487,7 +1497,7 @@ public class EwsExchangeSession extends ExchangeSession { protected static final HashMap GALFIND_ATTRIBUTE_MAP = new HashMap(); static { - GALFIND_ATTRIBUTE_MAP.put("uid", "Name"); + GALFIND_ATTRIBUTE_MAP.put("imapUid", "Name"); GALFIND_ATTRIBUTE_MAP.put("cn", "DisplayName"); GALFIND_ATTRIBUTE_MAP.put("givenName", "GivenName"); GALFIND_ATTRIBUTE_MAP.put("sn", "Surname"); @@ -1499,7 +1509,7 @@ public class EwsExchangeSession extends ExchangeSession { protected Contact buildGalfindContact(EWSMethod.Item response) { Contact contact = new Contact(); contact.setName(response.get("Name")); - contact.put("uid", response.get("Name")); + contact.put("imapUid", response.get("Name")); for (Map.Entry entry : GALFIND_ATTRIBUTE_MAP.entrySet()) { String attributeValue = response.get(entry.getValue()); if (attributeValue != null) { diff --git a/src/java/davmail/ldap/LdapConnection.java b/src/java/davmail/ldap/LdapConnection.java index 404379d9..4f3f27a3 100644 --- a/src/java/davmail/ldap/LdapConnection.java +++ b/src/java/davmail/ldap/LdapConnection.java @@ -27,7 +27,6 @@ import davmail.Settings; import davmail.exception.DavMailException; import davmail.exchange.ExchangeSession; import davmail.exchange.ExchangeSessionFactory; -import davmail.imap.ImapConnection; import davmail.ui.tray.DavGatewayTray; import org.apache.log4j.Logger; @@ -208,14 +207,14 @@ public class LdapConnection extends AbstractConnection { LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("nsaimid", "im"); LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("nscpaimscreenname", "im"); - LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("xmozillasecondemail", "email2"); + LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("xmozillasecondemail", "smtpemail2"); LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("notes", "description"); LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("pagerphone", "pager"); LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("locality", "l"); LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("homephone", "homePhone"); - LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillasecondemail", "email2"); + LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillasecondemail", "smtpemail2"); LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("zip", "postalcode"); LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillahomestate", "homeState"); diff --git a/src/test/davmail/ldap/TestLdap.java b/src/test/davmail/ldap/TestLdap.java index 73463722..b47b68b7 100644 --- a/src/test/davmail/ldap/TestLdap.java +++ b/src/test/davmail/ldap/TestLdap.java @@ -22,6 +22,7 @@ import davmail.DavGateway; import davmail.Settings; import davmail.exchange.AbstractExchangeSessionTestCase; import davmail.exchange.ExchangeSessionFactory; +import org.apache.log4j.Level; import javax.naming.NamingEnumeration; import javax.naming.NamingException; @@ -130,4 +131,11 @@ public class TestLdap extends AbstractExchangeSessionTestCase { searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE); NamingEnumeration searchResults = ldapContext.search("ou=people", "(postalcode=N18 1ZF)", searchControls); } + + public void testSearchByCnReturnSn() throws NamingException { + SearchControls searchControls = new SearchControls(); + searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE); + searchControls.setReturningAttributes(new String[]{"sn"}); + NamingEnumeration searchResults = ldapContext.search("ou=people", "(cn=*)", searchControls); + } }