mirror of
https://github.com/moparisthebest/davmail
synced 2025-03-05 11:49:46 -05:00
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:
parent
1669adf357
commit
1fed7df8c3
@ -821,7 +821,7 @@ public abstract class ExchangeSession {
|
|||||||
public abstract void appendTo(StringBuilder buffer);
|
public abstract void appendTo(StringBuilder buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract class AttributeCondition extends Condition {
|
protected abstract static class AttributeCondition extends Condition {
|
||||||
protected String attributeName;
|
protected String attributeName;
|
||||||
protected Operator operator;
|
protected Operator operator;
|
||||||
protected String value;
|
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 Operator operator;
|
||||||
protected Condition[] conditions;
|
protected Condition[] conditions;
|
||||||
|
|
||||||
protected MultiCondition(Operator operator, Condition... condition) {
|
protected MultiCondition(Operator operator, Condition... conditions) {
|
||||||
this.operator = operator;
|
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 or(Condition... condition);
|
||||||
|
|
||||||
|
protected abstract Condition not(Condition condition);
|
||||||
|
|
||||||
protected abstract AttributeCondition equals(String attributeName, String value);
|
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 folderName Exchange folder name
|
||||||
* @param recursive deep search if true
|
* @param recursive deep search if true
|
||||||
@ -858,8 +869,7 @@ public abstract class ExchangeSession {
|
|||||||
* @throws IOException on error
|
* @throws IOException on error
|
||||||
*/
|
*/
|
||||||
public List<Folder> getSubFolders(String folderName, boolean recursive) throws IOException {
|
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, or(equals("folderclass", "IPF.Note"), equals("folderclass", "IPF")), recursive);
|
||||||
return getSubFolders(folderName, equals("folderclass", "IPF.Note"), recursive);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -871,7 +881,6 @@ public abstract class ExchangeSession {
|
|||||||
* @throws IOException on error
|
* @throws IOException on error
|
||||||
*/
|
*/
|
||||||
public List<Folder> getSubCalendarFolders(String folderName, boolean recursive) throws IOException {
|
public List<Folder> getSubCalendarFolders(String folderName, boolean recursive) throws IOException {
|
||||||
// "\"DAV:contentclass\"='urn:content-classes:calendarfolder'"
|
|
||||||
return getSubFolders(folderName, equals("folderclass", "IPF.Appointment"), recursive);
|
return getSubFolders(folderName, equals("folderclass", "IPF.Appointment"), recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
protected MultiCondition(Operator operator, Condition... condition) {
|
||||||
super(operator, 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 final Map<String, String> attributeMap = new HashMap<String, String>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -204,7 +218,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
operatorMap.put(Operator.IsEqualTo, "=");
|
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) {
|
protected AttributeCondition(String attributeName, Operator operator, String value) {
|
||||||
super(attributeName, operator, value);
|
super(attributeName, operator, value);
|
||||||
}
|
}
|
||||||
@ -227,6 +241,11 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
return new MultiCondition(Operator.Or, condition);
|
return new MultiCondition(Operator.Or, condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Condition not(Condition condition) {
|
||||||
|
return new NotCondition(condition);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AttributeCondition equals(String attributeName, String value) {
|
protected AttributeCondition equals(String attributeName, String value) {
|
||||||
return new AttributeCondition(attributeName, Operator.IsEqualTo, value);
|
return new AttributeCondition(attributeName, Operator.IsEqualTo, value);
|
||||||
|
@ -210,6 +210,9 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
writer.write("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
|
writer.write("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
|
||||||
"xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" " +
|
"xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" " +
|
||||||
"xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\">" +
|
"xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\">" +
|
||||||
|
"<soap:Header>" +
|
||||||
|
"<t:RequestServerVersion Version=\"Exchange2007_SP1\"/>" +
|
||||||
|
"</soap:Header>"+
|
||||||
"<soap:Body>");
|
"<soap:Body>");
|
||||||
writer.write("<m:");
|
writer.write("<m:");
|
||||||
writer.write(methodName);
|
writer.write(methodName);
|
||||||
|
@ -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) {
|
protected MultiCondition(Operator operator, Condition... condition) {
|
||||||
super(operator, 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 final Map<String, FieldURI> attributeMap = new HashMap<String, FieldURI>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
attributeMap.put("folderclass", ExtendedFieldURI.PR_CONTAINER_CLASS);
|
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) {
|
protected AttributeCondition(String attributeName, Operator operator, String value) {
|
||||||
super(attributeName, operator, value);
|
super(attributeName, operator, value);
|
||||||
}
|
}
|
||||||
@ -119,6 +134,11 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
return new MultiCondition(Operator.Or, condition);
|
return new MultiCondition(Operator.Or, condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Condition not(Condition condition) {
|
||||||
|
return new NotCondition(condition);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AttributeCondition equals(String attributeName, String value) {
|
protected AttributeCondition equals(String attributeName, String value) {
|
||||||
return new AttributeCondition(attributeName, Operator.IsEqualTo, value);
|
return new AttributeCondition(attributeName, Operator.IsEqualTo, value);
|
||||||
@ -127,6 +147,7 @@ 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"));
|
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());
|
folder.etag = item.get(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME.getPropertyTag());
|
||||||
// TODO: implement ctag
|
// TODO: implement ctag
|
||||||
folder.ctag = String.valueOf(System.currentTimeMillis());
|
folder.ctag = String.valueOf(System.currentTimeMillis());
|
||||||
@ -142,7 +163,6 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<ExchangeSession.Folder> getSubFolders(String folderPath, Condition condition, boolean recursive) throws IOException {
|
public List<ExchangeSession.Folder> getSubFolders(String folderPath, Condition condition, boolean recursive) throws IOException {
|
||||||
|
|
||||||
List<ExchangeSession.Folder> folders = new ArrayList<ExchangeSession.Folder>();
|
List<ExchangeSession.Folder> folders = new ArrayList<ExchangeSession.Folder>();
|
||||||
appendSubFolders(folders, folderPath, getFolderId(folderPath), condition, recursive);
|
appendSubFolders(folders, folderPath, getFolderId(folderPath), condition, recursive);
|
||||||
return folders;
|
return folders;
|
||||||
@ -155,6 +175,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
findFolderMethod.setSearchExpression((SearchExpression) condition);
|
findFolderMethod.setSearchExpression((SearchExpression) condition);
|
||||||
findFolderMethod.addAdditionalProperty(ExtendedFieldURI.PR_URL_COMP_NAME);
|
findFolderMethod.addAdditionalProperty(ExtendedFieldURI.PR_URL_COMP_NAME);
|
||||||
findFolderMethod.addAdditionalProperty(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME);
|
findFolderMethod.addAdditionalProperty(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME);
|
||||||
|
findFolderMethod.addAdditionalProperty(ExtendedFieldURI.PR_CONTAINER_CLASS);
|
||||||
try {
|
try {
|
||||||
httpClient.executeMethod(findFolderMethod);
|
httpClient.executeMethod(findFolderMethod);
|
||||||
} finally {
|
} finally {
|
||||||
@ -198,10 +219,18 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static final String PUBLIC_ROOT = "/public";
|
||||||
|
|
||||||
private FolderId getFolderId(String folderPath) throws IOException {
|
private FolderId getFolderId(String folderPath) throws IOException {
|
||||||
FolderId currentFolderId = DistinguishedFolderId.MSGFOLDERROOT;
|
String[] folderNames;
|
||||||
String[] folderNames = folderPath.split("/");
|
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) {
|
for (String folderName : folderNames) {
|
||||||
if ("INBOX".equals(folderName)) {
|
if ("INBOX".equals(folderName)) {
|
||||||
currentFolderId = DistinguishedFolderId.INBOX;
|
currentFolderId = DistinguishedFolderId.INBOX;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user