From 92c8802dc2864d0d9e38e491a7eb11acd1df2780 Mon Sep 17 00:00:00 2001 From: mguessan Date: Wed, 3 Nov 2010 22:31:36 +0000 Subject: [PATCH] Ews: improve ResolveNames implementation, parse addresses and phone attributes git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1522 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../exchange/ews/EwsExchangeSession.java | 27 +++++++++++++++++++ .../exchange/ews/ResolveNamesMethod.java | 22 +++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index 75a15376..4cb6fa70 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -1660,12 +1660,39 @@ public class EwsExchangeSession extends ExchangeSession { GALFIND_ATTRIBUTE_MAP.put("email1", "EmailAddress1"); GALFIND_ATTRIBUTE_MAP.put("email2", "EmailAddress2"); GALFIND_ATTRIBUTE_MAP.put("email3", "EmailAddress3"); + + GALFIND_ATTRIBUTE_MAP.put("roomnumber", "OfficeLocation"); + GALFIND_ATTRIBUTE_MAP.put("street", "BusinessStreet"); + GALFIND_ATTRIBUTE_MAP.put("l", "BusinessCity"); + GALFIND_ATTRIBUTE_MAP.put("o", "CompanyName"); + GALFIND_ATTRIBUTE_MAP.put("postalcode", "BusinessPostalCode"); + + GALFIND_ATTRIBUTE_MAP.put("manager", "Manager"); + GALFIND_ATTRIBUTE_MAP.put("middlename", "Initials"); + GALFIND_ATTRIBUTE_MAP.put("title", "JobTitle"); + GALFIND_ATTRIBUTE_MAP.put("department", "Department"); + + GALFIND_ATTRIBUTE_MAP.put("otherTelephone", "AssistantPhone"); + GALFIND_ATTRIBUTE_MAP.put("telephoneNumber", "BusinessPhone"); + } + + protected static final HashSet IGNORE_ATTRIBUTE_SET = new HashSet(); + static { + IGNORE_ATTRIBUTE_SET.add("ContactSource"); + IGNORE_ATTRIBUTE_SET.add("Culture"); } protected Contact buildGalfindContact(EWSMethod.Item response) { Contact contact = new Contact(); contact.setName(response.get("Name")); contact.put("imapUid", response.get("Name")); + if (LOGGER.isDebugEnabled()) { + for (String key : response.keySet()) { + if (!IGNORE_ATTRIBUTE_SET.contains(key) && !GALFIND_ATTRIBUTE_MAP.containsValue(key)) { + LOGGER.debug("Unsupported ResolveNames response attribute: " + key + " value: " + response.get(key)); + } + } + } for (Map.Entry entry : GALFIND_ATTRIBUTE_MAP.entrySet()) { String attributeValue = response.get(entry.getValue()); if (attributeValue != null) { diff --git a/src/java/davmail/exchange/ews/ResolveNamesMethod.java b/src/java/davmail/exchange/ews/ResolveNamesMethod.java index 82067ef2..eb4d2f3b 100644 --- a/src/java/davmail/exchange/ews/ResolveNamesMethod.java +++ b/src/java/davmail/exchange/ews/ResolveNamesMethod.java @@ -93,12 +93,26 @@ public class ResolveNamesMethod extends EWSMethod { } } + protected void handlePhysicalAddress(XMLStreamReader reader, Item responseItem, String addressType) throws XMLStreamException { + while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "Entry")) { + reader.next(); + if (XMLStreamUtil.isStartTag(reader)) { + String tagLocalName = reader.getLocalName(); + String value = XMLStreamUtil.getElementText(reader); + responseItem.put(addressType+tagLocalName, value); + } + } + } + protected void handlePhysicalAddresses(XMLStreamReader reader, Item responseItem) throws XMLStreamException { while (reader.hasNext() && !XMLStreamUtil.isEndTag(reader, "PhysicalAddresses")) { reader.next(); if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); - // TODO + if ("Entry".equals(tagLocalName)) { + String key = getAttributeValue(reader, "Key"); + handlePhysicalAddress(reader, responseItem, key); + } } } } @@ -108,7 +122,11 @@ public class ResolveNamesMethod extends EWSMethod { reader.next(); if (XMLStreamUtil.isStartTag(reader)) { String tagLocalName = reader.getLocalName(); - // TODO + if ("Entry".equals(tagLocalName)) { + String key = getAttributeValue(reader, "Key"); + String value = XMLStreamUtil.getElementText(reader); + responseItem.put(key, value); + } } } }