1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 11:12:22 -05:00

LDAP: improve contact attribute mapping and add a few new properties

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1204 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-19 14:07:46 +00:00
parent 8bd80ecb8e
commit 77befe78f5
7 changed files with 122 additions and 24 deletions

View File

@ -1687,6 +1687,7 @@ public abstract class ExchangeSession {
writer.appendProperty("TEL;TYPE=home", get("homePhone"));
writer.appendProperty("TEL;TYPE=fax", get("facsimiletelephonenumber"));
writer.appendProperty("TEL;TYPE=pager", get("pager"));
writer.appendProperty("TEL;TYPE=car", get("othermobile"));
// The structured type value corresponds, in sequence, to the post office box; the extended address;
// the street address; the locality (e.g., city); the region (e.g., state or province);
@ -1704,6 +1705,7 @@ public abstract class ExchangeSession {
writer.appendProperty("ORG", get("o"), get("department"));
writer.appendProperty("URL;TYPE=work", get("businesshomepage"));
writer.appendProperty("URL;TYPE=home", get("personalHomePage"));
writer.appendProperty("TITLE", get("title"));
writer.appendProperty("NOTE", get("description"));
@ -2698,6 +2700,9 @@ public abstract class ExchangeSession {
if (property.hasParam("TYPE", "pager")) {
properties.put("pager", property.getValue());
}
if (property.hasParam("TYPE", "car")) {
properties.put("othermobile", property.getValue());
}
} else if ("ADR".equals(property.getKey())) {
// address
if (property.hasParam("TYPE", "home")) {
@ -2722,6 +2727,8 @@ public abstract class ExchangeSession {
} else if ("URL".equals(property.getKey())) {
if (property.hasParam("TYPE", "work")) {
properties.put("businesshomepage", property.getValue());
} else if (property.hasParam("TYPE", "home")) {
properties.put("personalHomePage", property.getValue());
}
} else if ("TITLE".equals(property.getKey())) {
properties.put("title", property.getValue());
@ -3127,6 +3134,7 @@ public abstract class ExchangeSession {
CONTACT_ATTRIBUTES.add("othercity");
CONTACT_ATTRIBUTES.add("haspicture");
CONTACT_ATTRIBUTES.add("keywords");
CONTACT_ATTRIBUTES.add("othermobile");
CONTACT_ATTRIBUTES.add("private");
CONTACT_ATTRIBUTES.add("sensitivity");

View File

@ -194,6 +194,7 @@ public class Field {
createField(URN_SCHEMAS_CONTACTS, "bday"); // PR_BIRTHDAY 0x3A42 SystemTime
createField(URN_SCHEMAS_CONTACTS, "businesshomepage"); // PR_BUSINESS_HOME_PAGE 0x3A51 String
createField(URN_SCHEMAS_CONTACTS, "personalHomePage"); // PR_PERSONAL_HOME_PAGE 0x3A50 String
//createField(URN_SCHEMAS_CONTACTS, "c"); // country DistinguishedPropertySetType.PublicStrings/urn:schemas:contacts:c/String
createField(URN_SCHEMAS_CONTACTS, "cn"); // PR_DISPLAY_NAME 0x3001 String
createField(URN_SCHEMAS_CONTACTS, "co"); // workAddressCountry DistinguishedPropertySetType.Address/0x00008049/String
@ -237,6 +238,8 @@ public class Field {
createField(URN_SCHEMAS_CONTACTS, "title"); // PR_TITLE 0x3A17 String
createField("description", URN_SCHEMAS_HTTPMAIL, "textdescription"); // PR_BODY 0x1000 String
createField("im", SCHEMAS_MAPI, "InstMsg"); // InstantMessagingAddress DistinguishedPropertySetType.Address/0x00008062/String
createField(URN_SCHEMAS_CONTACTS, "othermobile"); // PR_CAR_TELEPHONE_NUMBER 0x3A1E String
createField(URN_SCHEMAS_CONTACTS, "otherstreet"); // PR_OTHER_ADDRESS_STREET 0x3A63 String
createField(URN_SCHEMAS_CONTACTS, "otherstate"); // PR_OTHER_ADDRESS_STATE_OR_PROVINCE 0x3A62 String

View File

@ -83,6 +83,7 @@ public class Field {
FIELD_MAP.put("bday", new ExtendedFieldURI(0x3A42, ExtendedFieldURI.PropertyType.SystemTime));
FIELD_MAP.put("businesshomepage", new ExtendedFieldURI(0x3A51, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("personalHomePage", new ExtendedFieldURI(0x3A50, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("cn", new ExtendedFieldURI(0x3001, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("co", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Address, 0x8049, ExtendedFieldURI.PropertyType.String));
@ -124,6 +125,7 @@ public class Field {
FIELD_MAP.put("title", new ExtendedFieldURI(0x3A17, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("description", new ExtendedFieldURI(0x1000, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("im", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Address, 0x8062, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("othermobile", new ExtendedFieldURI(0x3A1E, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("otherstreet", new ExtendedFieldURI(0x3A63, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("otherstate", new ExtendedFieldURI(0x3A62, ExtendedFieldURI.PropertyType.String));

View File

@ -224,19 +224,86 @@ public class LdapConnection extends AbstractConnection {
static {
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("uid", "imapUid");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mail", "email1");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("displayname", "cn");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("cn", "cn");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("commonname", "cn");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("givenname", "givenName");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("sn", "sn");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("title", "title");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("surname", "sn");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("company", "o");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("o", "o");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("l", "l");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("department", "department");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("apple-group-realname", "department");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("description", "description");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillahomelocalityname", "homeCity");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("c", "c");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("c", "co");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("countryname", "co");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("custom1", "extensionattribute1");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("custom2", "extensionattribute2");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("custom3", "extensionattribute3");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("custom4", "extensionattribute4");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillacustom1", "extensionattribute1");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillacustom2", "extensionattribute2");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillacustom3", "extensionattribute3");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillacustom4", "extensionattribute4");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("telephonenumber", "telephoneNumber");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("orgunit", "department");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("departmentnumber", "department");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("ou", "department");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillaworkstreet2", null);
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillahomestreet", "homeStreet");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("xmozillanickname", "nickname");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillanickname", "nickname");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("cellphone", "mobile");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("homeurl", "personalHomePage");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillahomeurl", "personalHomePage");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillahomepostalcode", "homePostalCode");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("fax", "facsimiletelephonenumber");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillahomecountryname", "homeCountry");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("streetaddress", "street");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillaworkurl", "businesshomepage");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("workurl", "businesshomepage");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("region", "st");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("birthmonth", "bday");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("birthday", "bday");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("birthyear", "bday");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("carphone", "othermobile");
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("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("zip", "postalcode");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillahomestate", "homeState");
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("modifytimestamp", "lastmodified");
// ignore attribute
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("objectclass", null);
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillausehtmlmail", null);
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("xmozillausehtmlmail", null);
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("mozillahomestreet2", null);
LDAP_TO_CONTACT_ATTRIBUTE_MAP.put("labeleduri", null);
}
/**
@ -973,7 +1040,7 @@ public class LdapConnection extends AbstractConnection {
} else if (IGNORE_MAP.contains(attributeName)) {
// Ignore this specific attribute
return true;
} else if (CRITERIA_MAP.get(attributeName) == null && LDAP_TO_CONTACT_ATTRIBUTE_MAP.get(attributeName) == null) {
} else if (CRITERIA_MAP.get(attributeName) == null && getContactAttributeName(attributeName) == null) {
DavGatewayTray.debug(new BundleMessage("LOG_LDAP_UNSUPPORTED_FILTER_ATTRIBUTE",
attributeName, value));
@ -1013,7 +1080,7 @@ public class LdapConnection extends AbstractConnection {
}
public ExchangeSession.Condition getContactSearchFilter() {
String contactAttributeName = getContactAttributeName();
String contactAttributeName = getContactAttributeName(attributeName);
if (canIgnore || (contactAttributeName == null)) {
return null;
@ -1102,9 +1169,22 @@ public class LdapConnection extends AbstractConnection {
return CRITERIA_MAP.get(attributeName);
}
public String getContactAttributeName() {
return LDAP_TO_CONTACT_ATTRIBUTE_MAP.get(attributeName);
}
protected static String getContactAttributeName(String attributeName) {
String contactAttributeName = null;
// first look in contact attributes
if (ExchangeSession.CONTACT_ATTRIBUTES.contains(attributeName)) {
contactAttributeName = attributeName;
} else if (LDAP_TO_CONTACT_ATTRIBUTE_MAP.containsKey(attributeName)) {
String mappedAttribute = LDAP_TO_CONTACT_ATTRIBUTE_MAP.get(attributeName);
if (mappedAttribute != null) {
contactAttributeName = mappedAttribute;
}
} else {
DavGatewayTray.debug(new BundleMessage("UNKNOWN_ATTRIBUTE", attributeName));
}
return contactAttributeName;
}
protected class SearchThread extends Thread {
@ -1287,28 +1367,24 @@ public class LdapConnection extends AbstractConnection {
* @throws IOException on error
*/
public Map<String, Map<String, String>> contactFind(ExchangeSession.Condition condition, Set<String> returningAttributes) throws IOException {
Set<String> ldapReturningAttributes;
Set<String> contactReturningAttributes;
if (returningAttributes != null && !returningAttributes.isEmpty()) {
ldapReturningAttributes = new HashSet<String>();
contactReturningAttributes = new HashSet<String>();
// always return uid
ldapReturningAttributes.add("imapUid");
contactReturningAttributes.add("imapUid");
for (String attribute : returningAttributes) {
if (!"objectclass".equals(attribute)) {
String mappedAttribute = LDAP_TO_CONTACT_ATTRIBUTE_MAP.get(attribute);
if (mappedAttribute == null) {
ldapReturningAttributes.add(attribute);
} else {
ldapReturningAttributes.add(mappedAttribute);
}
String contactAttributeName = getContactAttributeName(attribute);
if (contactAttributeName != null) {
contactReturningAttributes.add(contactAttributeName);
}
}
} else {
ldapReturningAttributes = ExchangeSession.CONTACT_ATTRIBUTES;
contactReturningAttributes = ExchangeSession.CONTACT_ATTRIBUTES;
}
Map<String, Map<String, String>> results = new HashMap<String, Map<String, String>>();
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, ldapReturningAttributes, condition);
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, contactReturningAttributes, condition);
for (ExchangeSession.Contact contact : contacts) {
// TODO convert values

View File

@ -255,3 +255,4 @@ UI_IMAP_IDLE_DELAY=IDLE folder monitor delay (IMAP):
UI_IMAP_IDLE_DELAY_HELP=IMAP folder idle monitor delay in minutes, leave empty to disable IDLE support
EXCEPTION_EWS_NOT_AVAILABLE=EWS end point not available
EXCEPTION_FOLDER_NOT_FOUND=Folder {0} not found
UNKNOWN_ATTRIBUTE=Unknown attribute: {0}

View File

@ -255,3 +255,4 @@ UI_IMAP_AUTO_EXPUNGE=IMAP suppression imm
UI_IMAP_AUTO_EXPUNGE_HELP=Supprimer immédiatement les messages du serveur via IMAP
EXCEPTION_EWS_NOT_AVAILABLE=Point d''accès EWS non disponible
EXCEPTION_FOLDER_NOT_FOUND=Dossier {0} non trouvé
UNKNOWN_ATTRIBUTE=Attribut inconnu: {0}

View File

@ -76,4 +76,11 @@ public class TestLdap extends AbstractDavMailTestCase {
searchControls.setReturningAttributes(new String[]{"mail"});
NamingEnumeration<SearchResult> searchResults = ldapContext.search("ou=people", "(objectclass=*)", searchControls);
}
public void testMozillaSearchAttributes() throws NamingException {
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
searchControls.setReturningAttributes(new String[]{"custom1", "mozillausehtmlmail", "postalcode", "custom2", "custom3", "custom4", "street", "surname", "telephonenumber", "mozillahomelocalityname", "orgunit", "mozillaworkstreet2", "xmozillanickname", "mozillahomestreet", "description", "cellphone", "homeurl", "mozillahomepostalcode", "departmentnumber", "postofficebox", "st", "objectclass", "sn", "ou", "fax", "mozillahomeurl", "mozillahomecountryname", "streetaddress", "cn", "company", "mozillaworkurl", "mobile", "region", "birthmonth", "birthday", "labeleduri", "carphone", "department", "xmozillausehtmlmail", "givenname", "nsaimid", "workurl", "facsimiletelephonenumber", "mozillanickname", "title", "nscpaimscreenname", "xmozillasecondemail", "mozillacustom3", "countryname", "mozillacustom4", "mozillacustom1", "mozillacustom2", "homephone", "mozillasecondemail", "pager", "zip", "mail", "c", "mozillahomestate", "o", "l", "birthyear", "modifytimestamp", "locality", "commonname", "notes", "pagerphone", "mozillahomestreet2"});
NamingEnumeration<SearchResult> searchResults = ldapContext.search("ou=people", "(objectclass=*)", searchControls);
}
}