diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 886b7dd6..36958904 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -2486,6 +2486,7 @@ public abstract class ExchangeSession { ITEM_PROPERTIES.add("displayname"); // calendar CdoInstanceType ITEM_PROPERTIES.add("instancetype"); + ITEM_PROPERTIES.add("urlcompname"); } /** @@ -3084,6 +3085,7 @@ public abstract class ExchangeSession { static { CONTACT_ATTRIBUTES.add("imapUid"); CONTACT_ATTRIBUTES.add("etag"); + CONTACT_ATTRIBUTES.add("urlcompname"); CONTACT_ATTRIBUTES.add("extensionattribute1"); CONTACT_ATTRIBUTES.add("extensionattribute2"); diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index 018f931d..c9d1d84a 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -29,7 +29,6 @@ import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.methods.HeadMethod; -import org.apache.commons.httpclient.util.URIUtil; import javax.mail.MessagingException; import java.io.BufferedReader; @@ -115,6 +114,10 @@ public class EwsExchangeSession extends ExchangeSession { LOGGER.error(e.getMessage(), e); throw new DavMailAuthenticationException("EXCEPTION_EWS_NOT_AVAILABLE"); } + + // also need to retrieve email and alias + alias = getAliasFromOptions(); + email = getEmailFromOptions(); } class Message extends ExchangeSession.Message { @@ -656,6 +659,7 @@ public class EwsExchangeSession extends ExchangeSession { permanentUrl = response.get(Field.get("permanenturl").getResponseName()); etag = response.get(Field.get("etag").getResponseName()); displayName = response.get(Field.get("displayname").getResponseName()); + itemName = response.get(Field.get("urlcompname").getResponseName()); for (String attributeName : CONTACT_ATTRIBUTES) { String value = response.get(Field.get(attributeName).getResponseName()); if (value != null) { @@ -684,7 +688,7 @@ public class EwsExchangeSession extends ExchangeSession { list.add(Field.createFieldUpdate(entry.getKey(), entry.getValue())); } // force urlcompname - list.add(Field.createFieldUpdate("urlcompname", URIUtil.encodePath(convertItemNameToEML(itemName)))); + list.add(Field.createFieldUpdate("urlcompname", convertItemNameToEML(itemName))); return list; } @@ -789,8 +793,7 @@ public class EwsExchangeSession extends ExchangeSession { @Override public List searchContacts(String folderPath, Set attributes, Condition condition) throws IOException { List contacts = new ArrayList(); - List responses = searchItems(folderPath, attributes, - and(equals("outlookmessageclass", "IPM.Contact"), condition), + List responses = searchItems(folderPath, attributes,condition, FolderQueryTraversal.SHALLOW); for (EWSMethod.Item response : responses) { @@ -818,12 +821,13 @@ public class EwsExchangeSession extends ExchangeSession { EVENT_REQUEST_PROPERTIES.add("permanenturl"); EVENT_REQUEST_PROPERTIES.add("etag"); EVENT_REQUEST_PROPERTIES.add("displayname"); + EVENT_REQUEST_PROPERTIES.add("urlcompname"); } @Override public Item getItem(String folderPath, String itemName) throws IOException { - String urlcompname = URIUtil.encodePath(convertItemNameToEML(itemName)); + String urlcompname = convertItemNameToEML(itemName); List responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW); if (responses.isEmpty()) { throw new DavMailException("EXCEPTION_EVENT_NOT_FOUND"); @@ -848,7 +852,7 @@ public class EwsExchangeSession extends ExchangeSession { @Override public int deleteItem(String folderPath, String itemName) throws IOException { - String urlcompname = URIUtil.encodePath(convertItemNameToEML(itemName)); + String urlcompname = convertItemNameToEML(itemName); List responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW); if (!responses.isEmpty()) { DeleteItemMethod deleteItemMethod = new DeleteItemMethod(new ItemId(responses.get(0)), DeleteType.HardDelete); @@ -859,7 +863,7 @@ public class EwsExchangeSession extends ExchangeSession { @Override public int processItem(String folderPath, String itemName) throws IOException { - String urlcompname = URIUtil.encodePath(convertItemNameToEML(itemName)); + String urlcompname = convertItemNameToEML(itemName); List responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW); if (!responses.isEmpty()) { HashMap localProperties = new HashMap(); @@ -891,7 +895,8 @@ public class EwsExchangeSession extends ExchangeSession { @Override public boolean isSharedFolder(String folderPath) { - throw new UnsupportedOperationException(); + // TODO + return false; } @Override @@ -911,10 +916,13 @@ public class EwsExchangeSession extends ExchangeSession { private FolderId getFolderIdIfExists(String folderPath) throws IOException { String[] folderNames; FolderId currentFolderId; - if (folderPath.startsWith(PUBLIC_ROOT)) { + String currentMailboxPath = "/users/"+email+ '/'; + if (folderPath.startsWith(currentMailboxPath)) { + return getFolderIdIfExists(folderPath.substring(currentMailboxPath.length())); + } if (folderPath.startsWith(PUBLIC_ROOT)) { currentFolderId = DistinguishedFolderId.PUBLICFOLDERSROOT; folderNames = folderPath.substring(PUBLIC_ROOT.length()).split("/"); - } else if (folderPath.startsWith(INBOX)) { + } else if (folderPath.startsWith(INBOX) || folderPath.startsWith(LOWER_CASE_INBOX)) { currentFolderId = DistinguishedFolderId.INBOX; folderNames = folderPath.substring(INBOX.length()).split("/"); } else if (folderPath.startsWith(CALENDAR)) { diff --git a/src/java/davmail/exchange/ews/Field.java b/src/java/davmail/exchange/ews/Field.java index 0a0ba2ff..d5e07a86 100644 --- a/src/java/davmail/exchange/ews/Field.java +++ b/src/java/davmail/exchange/ews/Field.java @@ -35,6 +35,7 @@ public class Field { 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("instancetype", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "urn:schemas:calendar:instancetype")); // use PR_RECORD_KEY as unique key FIELD_MAP.put("uid", new ExtendedFieldURI(0x0FF9, ExtendedFieldURI.PropertyType.Binary)); @@ -57,7 +58,7 @@ public class Field { // contact - FIELD_MAP.put("outlookmessageclass", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Common, 0x001A, ExtendedFieldURI.PropertyType.String)); + FIELD_MAP.put("outlookmessageclass", new ExtendedFieldURI(0x001A, ExtendedFieldURI.PropertyType.String)); FIELD_MAP.put("subject", new ExtendedFieldURI(0x0037, ExtendedFieldURI.PropertyType.String)); FIELD_MAP.put("middlename", new ExtendedFieldURI(0x3A44, ExtendedFieldURI.PropertyType.String));