mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
LDAP: Additional Contact attributes
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@696 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
4e9e374ea1
commit
693f4cb0ed
@ -144,6 +144,7 @@ public class ExchangeSession {
|
|||||||
private static final String YYYY_MM_DD_HH_MM_SS = "yyyy/MM/dd HH:mm:ss";
|
private static final String YYYY_MM_DD_HH_MM_SS = "yyyy/MM/dd HH:mm:ss";
|
||||||
private static final String YYYYMMDD_T_HHMMSS_Z = "yyyyMMdd'T'HHmmss'Z'";
|
private static final String YYYYMMDD_T_HHMMSS_Z = "yyyyMMdd'T'HHmmss'Z'";
|
||||||
private static final String YYYY_MM_DD_T_HHMMSS_Z = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
private static final String YYYY_MM_DD_T_HHMMSS_Z = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
||||||
|
private static final String YYYY_MM_DD_T_HHMMSS_SSS_Z = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an exchange session for the given URL.
|
* Create an exchange session for the given URL.
|
||||||
@ -217,6 +218,12 @@ public class ExchangeSession {
|
|||||||
return dateFormat;
|
return dateFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected SimpleDateFormat getExchangeZuluDateFormatMillisecond() {
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat(YYYY_MM_DD_T_HHMMSS_SSS_Z, Locale.ENGLISH);
|
||||||
|
dateFormat.setTimeZone(GMT_TIMEZONE);
|
||||||
|
return dateFormat;
|
||||||
|
}
|
||||||
|
|
||||||
protected Date parseDate(String dateString) throws ParseException {
|
protected Date parseDate(String dateString) throws ParseException {
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||||
dateFormat.setTimeZone(GMT_TIMEZONE);
|
dateFormat.setTimeZone(GMT_TIMEZONE);
|
||||||
@ -2595,11 +2602,47 @@ public class ExchangeSession {
|
|||||||
*/
|
*/
|
||||||
public Map<String, Map<String, String>> contactFind(String searchFilter) throws IOException {
|
public Map<String, Map<String, String>> contactFind(String searchFilter) throws IOException {
|
||||||
StringBuilder searchRequest = new StringBuilder();
|
StringBuilder searchRequest = new StringBuilder();
|
||||||
searchRequest.append("Select \"DAV:uid\", \"urn:schemas:contacts:email1\", \"urn:schemas:contacts:cn\"," +
|
searchRequest.append("Select \"DAV:uid\", " +
|
||||||
" \"urn:schemas:contacts:givenName\",\"urn:schemas:contacts:sn\", \"urn:schemas:contacts:title\"," +
|
"\"http://schemas.microsoft.com/exchange/extensionattribute1\"," +
|
||||||
"\"urn:schemas:contacts:o\", \"urn:schemas:contacts:location\", \"urn:schemas:contacts:department\"," +
|
"\"http://schemas.microsoft.com/exchange/extensionattribute2\"," +
|
||||||
"\"urn:schemas:contacts:telephoneNumber\", \"urn:schemas:contacts:initials\", \"urn:schemas:contacts:street\"," +
|
"\"http://schemas.microsoft.com/exchange/extensionattribute3\"," +
|
||||||
"\"urn:schemas:contacts:st\", \"urn:schemas:contacts:c\", \"urn:schemas:contacts:mobile\"")
|
"\"http://schemas.microsoft.com/exchange/extensionattribute4\"," +
|
||||||
|
"\"urn:schemas:contacts:bday\"," +
|
||||||
|
"\"urn:schemas:contacts:businesshomepage\"," +
|
||||||
|
"\"urn:schemas:contacts:c\"," +
|
||||||
|
"\"urn:schemas:contacts:cn\"," +
|
||||||
|
"\"urn:schemas:contacts:co\"," +
|
||||||
|
"\"urn:schemas:contacts:department\"," +
|
||||||
|
"\"urn:schemas:contacts:email1\"," +
|
||||||
|
"\"urn:schemas:contacts:email2\"," +
|
||||||
|
"\"urn:schemas:contacts:facsimiletelephonenumber\"," +
|
||||||
|
"\"urn:schemas:contacts:givenName\"," +
|
||||||
|
"\"urn:schemas:contacts:homeCity\"," +
|
||||||
|
"\"urn:schemas:contacts:homeCountry\"," +
|
||||||
|
"\"urn:schemas:contacts:homePhone\"," +
|
||||||
|
"\"urn:schemas:contacts:homePostalCode\"," +
|
||||||
|
"\"urn:schemas:contacts:homeState\"," +
|
||||||
|
"\"urn:schemas:contacts:homeStreet\"," +
|
||||||
|
"\"urn:schemas:contacts:l\"," +
|
||||||
|
"\"urn:schemas:contacts:manager\"," +
|
||||||
|
"\"urn:schemas:contacts:mobile\"," +
|
||||||
|
"\"urn:schemas:contacts:namesuffix\"," +
|
||||||
|
"\"urn:schemas:contacts:nickname\"," +
|
||||||
|
"\"urn:schemas:contacts:o\"," +
|
||||||
|
"\"urn:schemas:contacts:pager\"," +
|
||||||
|
"\"urn:schemas:contacts:personaltitle\"," +
|
||||||
|
"\"urn:schemas:contacts:postalcode\"," +
|
||||||
|
"\"urn:schemas:contacts:postofficebox\"," +
|
||||||
|
"\"urn:schemas:contacts:profession\"," +
|
||||||
|
"\"urn:schemas:contacts:roomnumber\"," +
|
||||||
|
"\"urn:schemas:contacts:secretarycn\"," +
|
||||||
|
"\"urn:schemas:contacts:sn\"," +
|
||||||
|
"\"urn:schemas:contacts:spousecn\"," +
|
||||||
|
"\"urn:schemas:contacts:st\"," +
|
||||||
|
"\"urn:schemas:contacts:street\"," +
|
||||||
|
"\"urn:schemas:contacts:telephoneNumber\"," +
|
||||||
|
"\"urn:schemas:contacts:title\"," +
|
||||||
|
"\"urn:schemas:httpmail:textdescription\"")
|
||||||
.append(" FROM Scope('SHALLOW TRAVERSAL OF \"").append(contactsUrl).append("\"')\n");
|
.append(" FROM Scope('SHALLOW TRAVERSAL OF \"").append(contactsUrl).append("\"')\n");
|
||||||
if (searchFilter != null) {
|
if (searchFilter != null) {
|
||||||
searchRequest.append(" WHERE ").append(searchFilter);
|
searchRequest.append(" WHERE ").append(searchFilter);
|
||||||
@ -2618,16 +2661,29 @@ public class ExchangeSession {
|
|||||||
DavProperty property = propertiesIterator.nextProperty();
|
DavProperty property = propertiesIterator.nextProperty();
|
||||||
String propertyName = property.getName().getName();
|
String propertyName = property.getName().getName();
|
||||||
String propertyValue = (String) property.getValue();
|
String propertyValue = (String) property.getValue();
|
||||||
if ("email1".equals(propertyName)) {
|
if (propertyName.startsWith("email")) {
|
||||||
propertyName = "mail";
|
|
||||||
if (propertyValue != null && propertyValue.startsWith("\"")) {
|
if (propertyValue != null && propertyValue.startsWith("\"")) {
|
||||||
int endIndex = propertyValue.indexOf('\"', 1);
|
int endIndex = propertyValue.indexOf('\"', 1);
|
||||||
if (endIndex > 0) {
|
if (endIndex > 0) {
|
||||||
propertyValue = propertyValue.substring(1, endIndex);
|
propertyValue = propertyValue.substring(1, endIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (propertyValue != null && propertyValue.length() > 0) {
|
||||||
|
item.put(propertyName, propertyValue);
|
||||||
}
|
}
|
||||||
item.put(propertyName, propertyValue);
|
|
||||||
}
|
}
|
||||||
results.put(item.get("uid"), item);
|
results.put(item.get("uid"), item);
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,27 @@ public class LdapConnection extends AbstractConnection {
|
|||||||
ATTRIBUTE_MAP.put("mobile", "mobile");
|
ATTRIBUTE_MAP.put("mobile", "mobile");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static final HashMap<String, String> CONTACT_ATTRIBUTE_MAP = new HashMap<String, String>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("co", "countryname");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("extensionattribute1", "custom1");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("extensionattribute2", "custom2");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("extensionattribute3", "custom3");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("extensionattribute4", "custom4");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("email1", "mail");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("email2", "xmozillasecondemail");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("homeCountry", "mozillahomecountryname");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("homeCity", "mozillahomelocalityname");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("homePostalCode", "mozillahomepostalcode");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("homeState", "mozillahomestate");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("homeStreet", "mozillahomestreet");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("businesshomepage", "mozillaworkurl");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("textdescription", "notes");
|
||||||
|
CONTACT_ATTRIBUTE_MAP.put("nickname", "xmozillanickname");
|
||||||
|
}
|
||||||
|
|
||||||
static final HashMap<String, String> STATIC_ATTRIBUTE_MAP = new HashMap<String, String>();
|
static final HashMap<String, String> STATIC_ATTRIBUTE_MAP = new HashMap<String, String>();
|
||||||
|
|
||||||
static final String COMPUTER_GUID = "52486C30-F0AB-48E3-9C37-37E9B28CDD7B";
|
static final String COMPUTER_GUID = "52486C30-F0AB-48E3-9C37-37E9B28CDD7B";
|
||||||
@ -734,30 +755,39 @@ public class LdapConnection extends AbstractConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Map<String, String> person : persons.values()) {
|
for (Map<String, String> person : persons.values()) {
|
||||||
|
|
||||||
// add detailed information, only for GAL entries
|
|
||||||
if (needDetails && person.get("AN") != null) {
|
|
||||||
session.galLookup(person);
|
|
||||||
}
|
|
||||||
|
|
||||||
returningAttributes.add("uid");
|
returningAttributes.add("uid");
|
||||||
|
|
||||||
Map<String, Object> ldapPerson = new HashMap<String, Object>();
|
Map<String, Object> ldapPerson = new HashMap<String, Object>();
|
||||||
|
|
||||||
// Process all attributes that are mapped from exchange
|
// convert GAL entries
|
||||||
|
if (person.get("AN") != null) {
|
||||||
|
// add detailed information, only for GAL entries
|
||||||
|
if (needDetails) {
|
||||||
|
session.galLookup(person);
|
||||||
|
}
|
||||||
|
// Process all attributes that are mapped from exchange
|
||||||
|
for (Map.Entry<String, String> entry : ATTRIBUTE_MAP.entrySet()) {
|
||||||
|
String ldapAttribute = entry.getKey();
|
||||||
|
String exchangeAttribute = entry.getValue();
|
||||||
|
String value = person.get(exchangeAttribute);
|
||||||
|
// contactFind return ldap attributes directly
|
||||||
|
if (value == null) {
|
||||||
|
value = person.get(ldapAttribute);
|
||||||
|
}
|
||||||
|
if (value != null
|
||||||
|
&& (returnAllAttributes || returningAttributes.contains(ldapAttribute.toLowerCase()))) {
|
||||||
|
ldapPerson.put(ldapAttribute, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// convert Contact entries
|
||||||
|
for (Map.Entry<String, String> entry : person.entrySet()) {
|
||||||
|
String contactAttribute = entry.getKey();
|
||||||
|
String ldapAttribute = CONTACT_ATTRIBUTE_MAP.get(contactAttribute);
|
||||||
|
String value = entry.getValue();
|
||||||
|
ldapPerson.put(ldapAttribute == null ? contactAttribute : ldapAttribute, value);
|
||||||
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : ATTRIBUTE_MAP.entrySet()) {
|
|
||||||
String ldapAttribute = entry.getKey();
|
|
||||||
String exchangeAttribute = entry.getValue();
|
|
||||||
String value = person.get(exchangeAttribute);
|
|
||||||
// contactFind return ldap attributes directly
|
|
||||||
if (value == null) {
|
|
||||||
value = person.get(ldapAttribute);
|
|
||||||
}
|
|
||||||
if (value != null
|
|
||||||
&& (returnAllAttributes || returningAttributes.contains(ldapAttribute.toLowerCase()))) {
|
|
||||||
ldapPerson.put(ldapAttribute, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// iCal: copy cn to sn
|
// iCal: copy cn to sn
|
||||||
if (iCalSearch && ldapPerson.get("cn") != null) {
|
if (iCalSearch && ldapPerson.get("cn") != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user