diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 9c400c30..63536c6f 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -821,7 +821,7 @@ public abstract class ExchangeSession { public abstract void appendTo(StringBuilder buffer); } - protected abstract class AttributeCondition extends Condition { + protected abstract static class AttributeCondition extends Condition { protected String attributeName; protected Operator operator; protected String value; @@ -833,13 +833,21 @@ public abstract class ExchangeSession { } } - protected abstract class MultiCondition extends Condition { + protected abstract static class MultiCondition extends Condition { protected Operator operator; protected Condition[] conditions; - protected MultiCondition(Operator operator, Condition... condition) { + protected MultiCondition(Operator operator, Condition... conditions) { this.operator = operator; - conditions = condition; + this.conditions = conditions; + } + } + + protected abstract static class NotCondition extends Condition { + protected Condition condition; + + protected NotCondition(Condition condition) { + this.condition = condition; } } @@ -847,10 +855,13 @@ public abstract class ExchangeSession { protected abstract Condition or(Condition... condition); + protected abstract Condition not(Condition condition); + protected abstract AttributeCondition equals(String attributeName, String value); /** - * Search folders under given folder. + * Search mail and generic folders under given folder. + * Exclude calendar and contacts folders * * @param folderName Exchange folder name * @param recursive deep search if true @@ -858,8 +869,7 @@ public abstract class ExchangeSession { * @throws IOException on error */ public List getSubFolders(String folderName, boolean recursive) throws IOException { - // "(\"DAV:contentclass\"='urn:content-classes:mailfolder' OR \"DAV:contentclass\"='urn:content-classes:folder')" - return getSubFolders(folderName, equals("folderclass", "IPF.Note"), recursive); + return getSubFolders(folderName, or(equals("folderclass", "IPF.Note"), equals("folderclass", "IPF")), recursive); } /** @@ -871,7 +881,6 @@ public abstract class ExchangeSession { * @throws IOException on error */ public List getSubCalendarFolders(String folderName, boolean recursive) throws IOException { - // "\"DAV:contentclass\"='urn:content-classes:calendarfolder'" return getSubFolders(folderName, equals("folderclass", "IPF.Appointment"), recursive); } diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 257bd77a..e0536305 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -170,7 +170,7 @@ public class DavExchangeSession extends ExchangeSession { } } - protected class MultiCondition extends ExchangeSession.MultiCondition { + protected static class MultiCondition extends ExchangeSession.MultiCondition { protected MultiCondition(Operator operator, Condition... condition) { super(operator, condition); } @@ -191,6 +191,20 @@ public class DavExchangeSession extends ExchangeSession { } } + protected static class NotCondition extends ExchangeSession.NotCondition { + protected NotCondition(Condition condition) { + super(condition); + } + + @Override + public void appendTo(StringBuilder buffer) { + boolean first = true; + buffer.append("( Not "); + condition.appendTo(buffer); + buffer.append(')'); + } + } + static final Map attributeMap = new HashMap(); static { @@ -204,7 +218,7 @@ public class DavExchangeSession extends ExchangeSession { operatorMap.put(Operator.IsEqualTo, "="); } - protected class AttributeCondition extends ExchangeSession.AttributeCondition { + protected static class AttributeCondition extends ExchangeSession.AttributeCondition { protected AttributeCondition(String attributeName, Operator operator, String value) { super(attributeName, operator, value); } @@ -227,6 +241,11 @@ public class DavExchangeSession extends ExchangeSession { return new MultiCondition(Operator.Or, condition); } + @Override + protected Condition not(Condition condition) { + return new NotCondition(condition); + } + @Override protected AttributeCondition equals(String attributeName, String value) { return new AttributeCondition(attributeName, Operator.IsEqualTo, value); diff --git a/src/java/davmail/exchange/ews/EWSMethod.java b/src/java/davmail/exchange/ews/EWSMethod.java index d99d6595..feed606e 100644 --- a/src/java/davmail/exchange/ews/EWSMethod.java +++ b/src/java/davmail/exchange/ews/EWSMethod.java @@ -210,6 +210,9 @@ public abstract class EWSMethod extends PostMethod { writer.write("" + + "" + + "" + + ""+ ""); writer.write(""); + + condition.appendTo(buffer); + + buffer.append(""); + } + } + static final Map attributeMap = new HashMap(); static { attributeMap.put("folderclass", ExtendedFieldURI.PR_CONTAINER_CLASS); } - protected class AttributeCondition extends ExchangeSession.AttributeCondition implements SearchExpression { + protected static class AttributeCondition extends ExchangeSession.AttributeCondition implements SearchExpression { protected AttributeCondition(String attributeName, Operator operator, String value) { super(attributeName, operator, value); } @@ -119,6 +134,11 @@ public class EwsExchangeSession extends ExchangeSession { return new MultiCondition(Operator.Or, condition); } + @Override + protected Condition not(Condition condition) { + return new NotCondition(condition); + } + @Override protected AttributeCondition equals(String attributeName, String value) { return new AttributeCondition(attributeName, Operator.IsEqualTo, value); @@ -127,6 +147,7 @@ public class EwsExchangeSession extends ExchangeSession { protected Folder buildFolder(EWSMethod.Item item) { Folder folder = new Folder(); folder.folderId = new FolderId(item.get("FolderId")); + folder.folderClass = item.get(ExtendedFieldURI.PR_CONTAINER_CLASS.getPropertyTag()); folder.etag = item.get(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME.getPropertyTag()); // TODO: implement ctag folder.ctag = String.valueOf(System.currentTimeMillis()); @@ -142,7 +163,6 @@ public class EwsExchangeSession extends ExchangeSession { */ @Override public List getSubFolders(String folderPath, Condition condition, boolean recursive) throws IOException { - List folders = new ArrayList(); appendSubFolders(folders, folderPath, getFolderId(folderPath), condition, recursive); return folders; @@ -155,6 +175,7 @@ public class EwsExchangeSession extends ExchangeSession { findFolderMethod.setSearchExpression((SearchExpression) condition); findFolderMethod.addAdditionalProperty(ExtendedFieldURI.PR_URL_COMP_NAME); findFolderMethod.addAdditionalProperty(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME); + findFolderMethod.addAdditionalProperty(ExtendedFieldURI.PR_CONTAINER_CLASS); try { httpClient.executeMethod(findFolderMethod); } finally { @@ -198,10 +219,18 @@ public class EwsExchangeSession extends ExchangeSession { return folder; } + protected static final String PUBLIC_ROOT = "/public"; private FolderId getFolderId(String folderPath) throws IOException { - FolderId currentFolderId = DistinguishedFolderId.MSGFOLDERROOT; - String[] folderNames = folderPath.split("/"); + String[] folderNames; + FolderId currentFolderId; + if (folderPath.startsWith("/public")) { + currentFolderId = DistinguishedFolderId.PUBLICFOLDERSROOT; + folderNames = folderPath.substring(PUBLIC_ROOT.length()).split("/"); + } else { + currentFolderId = DistinguishedFolderId.MSGFOLDERROOT; + folderNames = folderPath.split("/"); + } for (String folderName : folderNames) { if ("INBOX".equals(folderName)) { currentFolderId = DistinguishedFolderId.INBOX;