1
0
mirror of https://github.com/moparisthebest/davmail synced 2025-01-13 06:28:19 -05:00

EWS: implement getItem and various contact handling fixes

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1148 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-07 12:29:41 +00:00
parent ff428fa307
commit 90df0e2fdf
4 changed files with 53 additions and 13 deletions

View File

@ -511,6 +511,10 @@ public abstract class EWSMethod extends PostMethod {
String tagLocalName = reader.getLocalName(); String tagLocalName = reader.getLocalName();
if (tagLocalName.equals("ExtendedFieldURI")) { if (tagLocalName.equals("ExtendedFieldURI")) {
propertyTag = getAttributeValue(reader, "PropertyTag"); propertyTag = getAttributeValue(reader, "PropertyTag");
// property name is in PropertyId with DistinguishedPropertySetId
if (propertyTag == null) {
propertyTag = getAttributeValue(reader, "PropertyId");
}
} else if (tagLocalName.equals("Value")) { } else if (tagLocalName.equals("Value")) {
propertyValue = reader.getElementText(); propertyValue = reader.getElementText();
} }

View File

@ -29,6 +29,7 @@ import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.httpclient.util.URIUtil;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -506,12 +507,12 @@ public class EwsExchangeSession extends ExchangeSession {
protected Folder buildFolder(EWSMethod.Item item) { protected Folder buildFolder(EWSMethod.Item item) {
Folder folder = new Folder(); Folder folder = new Folder();
folder.folderId = new FolderId(item.get("FolderId"), item.get("ChangeKey")); folder.folderId = new FolderId(item.get("FolderId"), item.get("ChangeKey"));
folder.displayName = item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getPropertyTag()); folder.displayName = item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getResponseName());
folder.folderClass = item.get(ExtendedFieldURI.PR_CONTAINER_CLASS.getPropertyTag()); folder.folderClass = item.get(ExtendedFieldURI.PR_CONTAINER_CLASS.getResponseName());
folder.etag = item.get(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME.getPropertyTag()); folder.etag = item.get(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME.getResponseName());
folder.ctag = item.get(ExtendedFieldURI.PR_LOCAL_COMMIT_TIME_MAX.getPropertyTag()); folder.ctag = item.get(ExtendedFieldURI.PR_LOCAL_COMMIT_TIME_MAX.getResponseName());
folder.unreadCount = item.getInt(ExtendedFieldURI.PR_CONTENT_UNREAD.getPropertyTag()); folder.unreadCount = item.getInt(ExtendedFieldURI.PR_CONTENT_UNREAD.getResponseName());
folder.hasChildren = item.getBoolean(ExtendedFieldURI.PR_SUBFOLDERS.getPropertyTag()); folder.hasChildren = item.getBoolean(ExtendedFieldURI.PR_SUBFOLDERS.getResponseName());
// noInferiors not implemented // noInferiors not implemented
return folder; return folder;
} }
@ -535,11 +536,11 @@ public class EwsExchangeSession extends ExchangeSession {
for (EWSMethod.Item item : findFolderMethod.getResponseItems()) { for (EWSMethod.Item item : findFolderMethod.getResponseItems()) {
Folder folder = buildFolder(item); Folder folder = buildFolder(item);
if (parentFolderPath.length() > 0) { if (parentFolderPath.length() > 0) {
folder.folderPath = parentFolderPath + '/' + item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getPropertyTag()); folder.folderPath = parentFolderPath + '/' + item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getResponseName());
} else if (folderIdMap.get(folder.folderId.value) != null) { } else if (folderIdMap.get(folder.folderId.value) != null) {
folder.folderPath = folderIdMap.get(folder.folderId.value); folder.folderPath = folderIdMap.get(folder.folderId.value);
} else { } else {
folder.folderPath = item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getPropertyTag()); folder.folderPath = item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getResponseName());
} }
folders.add(folder); folders.add(folder);
if (recursive && folder.hasChildren) { if (recursive && folder.hasChildren) {
@ -656,11 +657,11 @@ public class EwsExchangeSession extends ExchangeSession {
etag = response.get(Field.get("etag").getResponseName()); etag = response.get(Field.get("etag").getResponseName());
displayName = response.get(Field.get("displayname").getResponseName()); displayName = response.get(Field.get("displayname").getResponseName());
for (String attributeName : CONTACT_ATTRIBUTES) { for (String attributeName : CONTACT_ATTRIBUTES) {
String value = response.get(Field.get("attributeName").getResponseName()); String value = response.get(Field.get(attributeName).getResponseName());
if (value != null) { if (value != null) {
if ("bday".equals(attributeName) || "lastmodified".equals(attributeName)) { if ("bday".equals(attributeName) || "lastmodified".equals(attributeName)) {
try { try {
value = ExchangeSession.getZuluDateFormat().format(ExchangeSession.getExchangeZuluDateFormatMillisecond().parse(value)); value = ExchangeSession.getZuluDateFormat().format(ExchangeSession.getExchangeZuluDateFormat().parse(value));
} catch (ParseException e) { } catch (ParseException e) {
LOGGER.warn("Invalid date: " + value); LOGGER.warn("Invalid date: " + value);
} }
@ -682,7 +683,8 @@ public class EwsExchangeSession extends ExchangeSession {
for (Map.Entry<String, String> entry : entrySet()) { for (Map.Entry<String, String> entry : entrySet()) {
list.add(Field.createFieldUpdate(entry.getKey(), entry.getValue())); list.add(Field.createFieldUpdate(entry.getKey(), entry.getValue()));
} }
// force urlcompname
list.add(Field.createFieldUpdate("urlcompname", URIUtil.encodePath(convertItemNameToEML(itemName))));
return list; return list;
} }
@ -810,9 +812,33 @@ public class EwsExchangeSession extends ExchangeSession {
return events; return events;
} }
protected static final HashSet<String> EVENT_REQUEST_PROPERTIES = new HashSet<String>();
static {
EVENT_REQUEST_PROPERTIES.add("permanenturl");
EVENT_REQUEST_PROPERTIES.add("etag");
EVENT_REQUEST_PROPERTIES.add("displayname");
}
@Override @Override
public Item getItem(String folderPath, String itemName) throws IOException { public Item getItem(String folderPath, String itemName) throws IOException {
throw new UnsupportedOperationException(); String urlcompname = URIUtil.encodePath(convertItemNameToEML(itemName));
List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW);
if (responses.isEmpty()) {
throw new DavMailException("EXCEPTION_EVENT_NOT_FOUND");
}
String itemType = responses.get(0).type;
if ("Contact".equals(itemType)) {
// retrieve Contact properties
// TODO: need to check list size
return searchContacts(folderPath, CONTACT_ATTRIBUTES, equals("urlcompname", urlcompname)).get(0);
} else if ("CalendarItem".equals(itemType)
|| "MeetingRequest".equals(itemType)) {
return new Event(responses.get(0));
} else {
throw new DavMailException("EXCEPTION_EVENT_NOT_FOUND");
}
} }
@Override @Override

View File

@ -108,7 +108,11 @@ public class ExtendedFieldURI implements FieldURI {
} }
public String getResponseName() { public String getResponseName() {
if (propertyTag != null) {
return propertyTag; return propertyTag;
} else {
return String.valueOf(propertyId);
}
} }
public static final ExtendedFieldURI PR_INSTANCE_KEY = new ExtendedFieldURI(0xff6, PropertyType.Binary); public static final ExtendedFieldURI PR_INSTANCE_KEY = new ExtendedFieldURI(0xff6, PropertyType.Binary);

View File

@ -28,6 +28,12 @@ public class Field {
protected static final Map<String, FieldURI> FIELD_MAP = new HashMap<String, FieldURI>(); protected static final Map<String, FieldURI> FIELD_MAP = new HashMap<String, FieldURI>();
static { static {
// items
FIELD_MAP.put("etag", new ExtendedFieldURI(0x3008, ExtendedFieldURI.PropertyType.SystemTime));
FIELD_MAP.put("displayname", new ExtendedFieldURI(0x3001, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("urlcompname", new ExtendedFieldURI(0x10f3, ExtendedFieldURI.PropertyType.String));
FIELD_MAP.put("lastmodified", new ExtendedFieldURI(0x3008, ExtendedFieldURI.PropertyType.SystemTime));
FIELD_MAP.put("permanenturl", new ExtendedFieldURI(0x670E, ExtendedFieldURI.PropertyType.String)); //PR_FLAT_URL_NAME FIELD_MAP.put("permanenturl", new ExtendedFieldURI(0x670E, ExtendedFieldURI.PropertyType.String)); //PR_FLAT_URL_NAME
// use PR_RECORD_KEY as unique key // use PR_RECORD_KEY as unique key