EWS: implement NotCondition and public folder access

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1080 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-06-07 22:30:23 +00:00
parent 1669adf357
commit 1fed7df8c3
4 changed files with 75 additions and 15 deletions

View File

@ -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<Folder> 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<Folder> getSubCalendarFolders(String folderName, boolean recursive) throws IOException {
// "\"DAV:contentclass\"='urn:content-classes:calendarfolder'"
return getSubFolders(folderName, equals("folderclass", "IPF.Appointment"), recursive);
}

View File

@ -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<String, String> attributeMap = new HashMap<String, String>();
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);

View File

@ -210,6 +210,9 @@ public abstract class EWSMethod extends PostMethod {
writer.write("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" " +
"xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\">" +
"<soap:Header>" +
"<t:RequestServerVersion Version=\"Exchange2007_SP1\"/>" +
"</soap:Header>"+
"<soap:Body>");
writer.write("<m:");
writer.write(methodName);

View File

@ -68,7 +68,7 @@ public class EwsExchangeSession extends ExchangeSession {
}
}
protected class MultiCondition extends ExchangeSession.MultiCondition implements SearchExpression {
protected static class MultiCondition extends ExchangeSession.MultiCondition implements SearchExpression {
protected MultiCondition(Operator operator, Condition... condition) {
super(operator, condition);
}
@ -85,13 +85,28 @@ public class EwsExchangeSession extends ExchangeSession {
}
}
protected static class NotCondition extends ExchangeSession.NotCondition implements SearchExpression {
protected NotCondition(Condition condition) {
super(condition);
}
@Override
public void appendTo(StringBuilder buffer) {
buffer.append("<t:Not>");
condition.appendTo(buffer);
buffer.append("</t:Not>");
}
}
static final Map<String, FieldURI> attributeMap = new HashMap<String, FieldURI>();
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<ExchangeSession.Folder> getSubFolders(String folderPath, Condition condition, boolean recursive) throws IOException {
List<ExchangeSession.Folder> folders = new ArrayList<ExchangeSession.Folder>();
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;