mirror of
https://github.com/moparisthebest/davmail
synced 2025-03-04 19:29:46 -05:00
LDAP: fix contact attributes reverse mapping
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1205 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
77befe78f5
commit
ca090b7cbb
@ -35,6 +35,8 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1171,22 +1173,43 @@ public class LdapConnection extends AbstractConnection {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String getContactAttributeName(String attributeName) {
|
/**
|
||||||
|
* Convert contact attribute name to LDAP attribute name.
|
||||||
|
*
|
||||||
|
* @param ldapAttributeName ldap attribute name
|
||||||
|
* @return contact attribute name
|
||||||
|
*/
|
||||||
|
protected static String getContactAttributeName(String ldapAttributeName) {
|
||||||
String contactAttributeName = null;
|
String contactAttributeName = null;
|
||||||
// first look in contact attributes
|
// first look in contact attributes
|
||||||
if (ExchangeSession.CONTACT_ATTRIBUTES.contains(attributeName)) {
|
if (ExchangeSession.CONTACT_ATTRIBUTES.contains(ldapAttributeName)) {
|
||||||
contactAttributeName = attributeName;
|
contactAttributeName = ldapAttributeName;
|
||||||
} else if (LDAP_TO_CONTACT_ATTRIBUTE_MAP.containsKey(attributeName)) {
|
} else if (LDAP_TO_CONTACT_ATTRIBUTE_MAP.containsKey(ldapAttributeName)) {
|
||||||
String mappedAttribute = LDAP_TO_CONTACT_ATTRIBUTE_MAP.get(attributeName);
|
String mappedAttribute = LDAP_TO_CONTACT_ATTRIBUTE_MAP.get(ldapAttributeName);
|
||||||
if (mappedAttribute != null) {
|
if (mappedAttribute != null) {
|
||||||
contactAttributeName = mappedAttribute;
|
contactAttributeName = mappedAttribute;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DavGatewayTray.debug(new BundleMessage("UNKNOWN_ATTRIBUTE", attributeName));
|
DavGatewayTray.debug(new BundleMessage("UNKNOWN_ATTRIBUTE", ldapAttributeName));
|
||||||
}
|
}
|
||||||
return contactAttributeName;
|
return contactAttributeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert LDAP attribute name to contact attribute name.
|
||||||
|
*
|
||||||
|
* @param contactAttributeName ldap attribute name
|
||||||
|
* @return contact attribute name
|
||||||
|
*/
|
||||||
|
protected static String getLdapAttributeName(String contactAttributeName) {
|
||||||
|
String mappedAttributeName = CONTACT_TO_LDAP_ATTRIBUTE_MAP.get(contactAttributeName);
|
||||||
|
if (mappedAttributeName != null) {
|
||||||
|
return contactAttributeName;
|
||||||
|
} else {
|
||||||
|
return mappedAttributeName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected class SearchThread extends Thread {
|
protected class SearchThread extends Thread {
|
||||||
private final int currentMessageId;
|
private final int currentMessageId;
|
||||||
private final String dn;
|
private final String dn;
|
||||||
@ -1387,24 +1410,6 @@ public class LdapConnection extends AbstractConnection {
|
|||||||
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, contactReturningAttributes, condition);
|
List<ExchangeSession.Contact> contacts = session.searchContacts(ExchangeSession.CONTACTS, contactReturningAttributes, condition);
|
||||||
|
|
||||||
for (ExchangeSession.Contact contact : contacts) {
|
for (ExchangeSession.Contact contact : contacts) {
|
||||||
// TODO convert values
|
|
||||||
/*
|
|
||||||
if ("bday".equals(propertyName)) {
|
|
||||||
SimpleDateFormat parser = getExchangeZuluDateFormatMillisecond();
|
|
||||||
try {
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.setTime(parser.parse(propertyValue));
|
|
||||||
item.put("birthday", String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
|
|
||||||
item.put("birthmonth", String.valueOf(calendar.get(Calendar.MONTH) + 1));
|
|
||||||
item.put("birthyear", String.valueOf(calendar.get(Calendar.YEAR)));
|
|
||||||
propertyValue = null;
|
|
||||||
} catch (ParseException e) {
|
|
||||||
throw new IOException(e);
|
|
||||||
}
|
|
||||||
} else if ("description".equals(propertyName) && " \n".equals(propertyValue)) {
|
|
||||||
propertyValue = null;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (contact.get("imapUid") != null) {
|
if (contact.get("imapUid") != null) {
|
||||||
results.put(contact.get("imapUid"), contact);
|
results.put(contact.get("imapUid"), contact);
|
||||||
}
|
}
|
||||||
@ -1477,18 +1482,39 @@ public class LdapConnection extends AbstractConnection {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// convert Contact entries
|
// convert Contact entries
|
||||||
for (Map.Entry<String, String> entry : person.entrySet()) {
|
if (returnAllAttributes) {
|
||||||
String contactAttribute = entry.getKey();
|
// just convert contact attributes to default ldap names
|
||||||
// get converted attribute name
|
for (Map.Entry<String, String> entry : person.entrySet()) {
|
||||||
String ldapAttribute = CONTACT_TO_LDAP_ATTRIBUTE_MAP.get(contactAttribute);
|
String ldapAttribute = getLdapAttributeName(entry.getKey());
|
||||||
// no conversion, use exchange attribute name
|
String value = entry.getValue();
|
||||||
if (ldapAttribute == null) {
|
if (value != null) {
|
||||||
ldapAttribute = contactAttribute;
|
ldapPerson.put(ldapAttribute, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String value = entry.getValue();
|
} else {
|
||||||
if (value != null
|
// iterate over requested attributes
|
||||||
&& (returnAllAttributes || returningAttributes.contains(ldapAttribute.toLowerCase()))) {
|
for (String ldapAttribute : returningAttributes) {
|
||||||
ldapPerson.put(ldapAttribute, value);
|
String contactAttribute = getContactAttributeName(ldapAttribute);
|
||||||
|
String value = person.get(contactAttribute);
|
||||||
|
if (value != null) {
|
||||||
|
if (ldapAttribute.startsWith("birth")) {
|
||||||
|
SimpleDateFormat parser = session.getZuluDateFormat();
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
try {
|
||||||
|
calendar.setTime(parser.parse(value));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
if ("birthday".equals(ldapAttribute)) {
|
||||||
|
value = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
|
||||||
|
} else if ("birthmonth".equals(ldapAttribute)) {
|
||||||
|
value = String.valueOf(calendar.get(Calendar.MONTH) + 1);
|
||||||
|
} else if ("birthyear".equals(ldapAttribute)) {
|
||||||
|
value = String.valueOf(calendar.get(Calendar.YEAR));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ldapPerson.put(ldapAttribute, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user