mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-14 11:42:23 -05:00
EWS: Various fixes after refactoring on DASL request generation
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1091 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
d344693d1e
commit
2b9d0061c0
@ -742,6 +742,8 @@ public abstract class ExchangeSession {
|
|||||||
|
|
||||||
public abstract Condition equals(String attributeName, String value);
|
public abstract Condition equals(String attributeName, String value);
|
||||||
|
|
||||||
|
public abstract Condition equals(String attributeName, int value);
|
||||||
|
|
||||||
public abstract Condition headerEquals(String headerName, String value);
|
public abstract Condition headerEquals(String headerName, String value);
|
||||||
|
|
||||||
public abstract Condition gte(String attributeName, String value);
|
public abstract Condition gte(String attributeName, String value);
|
||||||
@ -2586,7 +2588,7 @@ public abstract class ExchangeSession {
|
|||||||
public List<Event> getEventMessages(String folderPath) throws IOException {
|
public List<Event> getEventMessages(String folderPath) throws IOException {
|
||||||
return searchEvents(folderPath, ITEM_PROPERTIES,
|
return searchEvents(folderPath, ITEM_PROPERTIES,
|
||||||
and(equals("contentclass", "urn:content-classes:calendarmessage"),
|
and(equals("contentclass", "urn:content-classes:calendarmessage"),
|
||||||
isFalse("processed")));
|
or(isNull("processed"), isFalse("processed"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2614,8 +2616,8 @@ public abstract class ExchangeSession {
|
|||||||
|
|
||||||
return searchEvents(folderPath, ITEM_PROPERTIES,
|
return searchEvents(folderPath, ITEM_PROPERTIES,
|
||||||
and(or(isNull("instancetype"),
|
and(or(isNull("instancetype"),
|
||||||
equals("instancetype", "1"),
|
equals("instancetype", 1),
|
||||||
and(equals("instancetype", "0"), dateCondition)),
|
and(equals("instancetype", 0), dateCondition)),
|
||||||
equals("contentclass", "urn:content-classes:appointment"),
|
equals("contentclass", "urn:content-classes:appointment"),
|
||||||
privateCondition));
|
privateCondition));
|
||||||
}
|
}
|
||||||
|
@ -272,19 +272,29 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
operatorMap.put(Operator.IsLessThan, " < ");
|
operatorMap.put(Operator.IsLessThan, " < ");
|
||||||
operatorMap.put(Operator.Like, " like ");
|
operatorMap.put(Operator.Like, " like ");
|
||||||
operatorMap.put(Operator.IsNull, " is null");
|
operatorMap.put(Operator.IsNull, " is null");
|
||||||
operatorMap.put(Operator.IsFalse, " is false");
|
operatorMap.put(Operator.IsFalse, " = false");
|
||||||
|
operatorMap.put(Operator.IsTrue, " = true");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class AttributeCondition extends ExchangeSession.AttributeCondition {
|
protected static class AttributeCondition extends ExchangeSession.AttributeCondition {
|
||||||
|
protected boolean isIntValue = false;
|
||||||
|
|
||||||
protected AttributeCondition(String attributeName, Operator operator, String value) {
|
protected AttributeCondition(String attributeName, Operator operator, String value) {
|
||||||
super(attributeName, operator, value);
|
super(attributeName, operator, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected AttributeCondition(String attributeName, Operator operator, int value) {
|
||||||
|
super(attributeName, operator, String.valueOf(value));
|
||||||
|
isIntValue = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendTo(StringBuilder buffer) {
|
public void appendTo(StringBuilder buffer) {
|
||||||
buffer.append('"').append(Field.get(attributeName).getUri()).append('"');
|
buffer.append('"').append(Field.get(attributeName).getUri()).append('"');
|
||||||
buffer.append(operatorMap.get(operator));
|
buffer.append(operatorMap.get(operator));
|
||||||
|
if (!isIntValue) {
|
||||||
buffer.append('\'');
|
buffer.append('\'');
|
||||||
|
}
|
||||||
if (Operator.Like == operator) {
|
if (Operator.Like == operator) {
|
||||||
buffer.append('%');
|
buffer.append('%');
|
||||||
}
|
}
|
||||||
@ -292,9 +302,11 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
if (Operator.Like == operator) {
|
if (Operator.Like == operator) {
|
||||||
buffer.append('%');
|
buffer.append('%');
|
||||||
}
|
}
|
||||||
|
if (!isIntValue) {
|
||||||
buffer.append('\'');
|
buffer.append('\'');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected static class HeaderCondition extends AttributeCondition {
|
protected static class HeaderCondition extends AttributeCondition {
|
||||||
|
|
||||||
@ -354,6 +366,11 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
return new AttributeCondition(attributeName, Operator.IsEqualTo, value);
|
return new AttributeCondition(attributeName, Operator.IsEqualTo, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Condition equals(String attributeName, int value) {
|
||||||
|
return new AttributeCondition(attributeName, Operator.IsEqualTo, value);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition headerEquals(String headerName, String value) {
|
public Condition headerEquals(String headerName, String value) {
|
||||||
return new HeaderCondition(headerName, Operator.IsEqualTo, value);
|
return new HeaderCondition(headerName, Operator.IsEqualTo, value);
|
||||||
@ -428,9 +445,9 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
public Event(MultiStatusResponse multiStatusResponse) throws URIException {
|
public Event(MultiStatusResponse multiStatusResponse) throws URIException {
|
||||||
href = URIUtil.decode(multiStatusResponse.getHref());
|
href = URIUtil.decode(multiStatusResponse.getHref());
|
||||||
DavPropertySet properties = multiStatusResponse.getProperties(HttpStatus.SC_OK);
|
DavPropertySet properties = multiStatusResponse.getProperties(HttpStatus.SC_OK);
|
||||||
permanentUrl = getPropertyIfExists(properties, "permanenturl", SCHEMAS_EXCHANGE);
|
permanentUrl = getPropertyIfExists(properties, "permanenturl");
|
||||||
etag = getPropertyIfExists(properties, "getetag", DAV);
|
etag = getPropertyIfExists(properties, "etag");
|
||||||
displayName = getPropertyIfExists(properties, "displayname", DAV);
|
displayName = getPropertyIfExists(properties, "displayname");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event(String messageUrl, String contentClass, String itemBody, String etag, String noneMatch) {
|
public Event(String messageUrl, String contentClass, String itemBody, String etag, String noneMatch) {
|
||||||
@ -651,8 +668,8 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getPropertyIfExists(DavPropertySet properties, String name) {
|
protected String getPropertyIfExists(DavPropertySet properties, String alias) {
|
||||||
DavProperty property = properties.get(name, EMPTY);
|
DavProperty property = properties.get(Field.getResponsePropertyName(alias));
|
||||||
if (property == null) {
|
if (property == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
@ -660,8 +677,8 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getIntPropertyIfExists(DavPropertySet properties, String name) {
|
protected int getIntPropertyIfExists(DavPropertySet properties, String alias) {
|
||||||
DavProperty property = properties.get(name, EMPTY);
|
DavProperty property = properties.get(Field.getResponsePropertyName(alias));
|
||||||
if (property == null) {
|
if (property == null) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@ -669,8 +686,8 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected long getLongPropertyIfExists(DavPropertySet properties, String name) {
|
protected long getLongPropertyIfExists(DavPropertySet properties, String alias) {
|
||||||
DavProperty property = properties.get(name, EMPTY);
|
DavProperty property = properties.get(Field.getResponsePropertyName(alias));
|
||||||
if (property == null) {
|
if (property == null) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@ -768,14 +785,15 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
public MultiStatusResponse[] searchItems(String folderName, List<String> attributes, Condition condition) throws IOException {
|
public MultiStatusResponse[] searchItems(String folderName, List<String> attributes, Condition condition) throws IOException {
|
||||||
String folderUrl = getFolderPath(folderName);
|
String folderUrl = getFolderPath(folderName);
|
||||||
StringBuilder searchRequest = new StringBuilder();
|
StringBuilder searchRequest = new StringBuilder();
|
||||||
searchRequest.append("Select \"http://schemas.microsoft.com/exchange/permanenturl\" as permanenturl");
|
searchRequest.append("SELECT ")
|
||||||
|
.append(Field.getRequestPropertyString("permanenturl"));
|
||||||
if (attributes != null) {
|
if (attributes != null) {
|
||||||
for (String attribute : attributes) {
|
for (String attribute : attributes) {
|
||||||
Field field = Field.get(attribute);
|
Field field = Field.get(attribute);
|
||||||
searchRequest.append(",\"").append(field.getUri()).append("\" as ").append(field.getAlias());
|
searchRequest.append(',').append(Field.getRequestPropertyString(field.getAlias()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
searchRequest.append(" FROM Scope('SHALLOW TRAVERSAL OF \"").append(folderUrl).append("\"')")
|
searchRequest.append(" FROM SCOPE('SHALLOW TRAVERSAL OF \"").append(folderUrl).append("\"')")
|
||||||
.append(" WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False");
|
.append(" WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False");
|
||||||
if (condition != null) {
|
if (condition != null) {
|
||||||
searchRequest.append(" AND ");
|
searchRequest.append(" AND ");
|
||||||
|
@ -61,6 +61,9 @@ public class Field {
|
|||||||
'{' + distinguishedPropertySetMap.get(DistinguishedPropertySetType.InternetHeaders) + "}/");
|
'{' + distinguishedPropertySetMap.get(DistinguishedPropertySetType.InternetHeaders) + "}/");
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property type list from EWS
|
||||||
|
*/
|
||||||
protected static enum PropertyType {
|
protected static enum PropertyType {
|
||||||
ApplicationTime, ApplicationTimeArray, Binary, BinaryArray, Boolean, CLSID, CLSIDArray, Currency, CurrencyArray,
|
ApplicationTime, ApplicationTimeArray, Binary, BinaryArray, Boolean, CLSID, CLSIDArray, Currency, CurrencyArray,
|
||||||
Double, DoubleArray, Error, Float, FloatArray, Integer, IntegerArray, Long, LongArray, Null, Object,
|
Double, DoubleArray, Error, Float, FloatArray, Integer, IntegerArray, Long, LongArray, Null, Object,
|
||||||
@ -116,7 +119,7 @@ public class Field {
|
|||||||
createField("iconIndex", 0x1080, PropertyType.Integer);//PR_ICON_INDEX
|
createField("iconIndex", 0x1080, PropertyType.Integer);//PR_ICON_INDEX
|
||||||
createField(URN_SCHEMAS_HTTPMAIL, "read");
|
createField(URN_SCHEMAS_HTTPMAIL, "read");
|
||||||
//createField("read", 0x0e69, PropertyType.Boolean);//PR_READ
|
//createField("read", 0x0e69, PropertyType.Boolean);//PR_READ
|
||||||
createField("deleted", DistinguishedPropertySetType.Common, 0x8570);
|
createField("deleted", DistinguishedPropertySetType.Common, 0x8570, "deleted");
|
||||||
createField("writedeleted", DistinguishedPropertySetType.Common, 0x8570, PropertyType.Custom);
|
createField("writedeleted", DistinguishedPropertySetType.Common, 0x8570, PropertyType.Custom);
|
||||||
// http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/0x8506 private
|
// http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/0x8506 private
|
||||||
createField(URN_SCHEMAS_HTTPMAIL, "date");//PR_CLIENT_SUBMIT_TIME, 0x0039
|
createField(URN_SCHEMAS_HTTPMAIL, "date");//PR_CLIENT_SUBMIT_TIME, 0x0039
|
||||||
@ -158,9 +161,9 @@ public class Field {
|
|||||||
fieldMap.put(field.alias, field);
|
fieldMap.put(field.alias, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void createField(String alias, DistinguishedPropertySetType propertySetType, int propertyTag) {
|
protected static void createField(String alias, DistinguishedPropertySetType propertySetType, int propertyTag, String responseAlias) {
|
||||||
String name = '{' + distinguishedPropertySetMap.get(propertySetType) + "}/0x" + Integer.toHexString(propertyTag);
|
String name = '{' + distinguishedPropertySetMap.get(propertySetType) + "}/0x" + Integer.toHexString(propertyTag);
|
||||||
Field field = new Field(alias, SCHEMAS_MAPI_ID, name);
|
Field field = new Field(alias, SCHEMAS_MAPI_ID, name, responseAlias);
|
||||||
fieldMap.put(field.alias, field);
|
fieldMap.put(field.alias, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,15 +188,25 @@ public class Field {
|
|||||||
protected final DavPropertyName davPropertyName;
|
protected final DavPropertyName davPropertyName;
|
||||||
protected final String alias;
|
protected final String alias;
|
||||||
protected final String uri;
|
protected final String uri;
|
||||||
|
protected final String requestPropertyString;
|
||||||
|
|
||||||
public Field(Namespace namespace, String name) {
|
public Field(Namespace namespace, String name) {
|
||||||
this(name, namespace, name);
|
this(name, namespace, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Field(String alias, Namespace namespace, String name) {
|
public Field(String alias, Namespace namespace, String name) {
|
||||||
|
this(alias, namespace, name, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Field(String alias, Namespace namespace, String name, String responseAlias) {
|
||||||
davPropertyName = DavPropertyName.create(name, namespace);
|
davPropertyName = DavPropertyName.create(name, namespace);
|
||||||
this.alias = alias;
|
this.alias = alias;
|
||||||
this.uri = namespace.getURI() + name;
|
this.uri = namespace.getURI() + name;
|
||||||
|
if (responseAlias == null) {
|
||||||
|
this.requestPropertyString = '"' + uri + '"';
|
||||||
|
} else {
|
||||||
|
this.requestPropertyString = '"' + uri + "\" as " + responseAlias;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
@ -236,4 +249,13 @@ public class Field {
|
|||||||
return new DefaultDavProperty(Field.get(alias).davPropertyName, value);
|
return new DefaultDavProperty(Field.get(alias).davPropertyName, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static DavPropertyName getResponsePropertyName(String alias) {
|
||||||
|
return Field.get(alias).davPropertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getRequestPropertyString(String alias) {
|
||||||
|
return Field.get(alias).requestPropertyString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,6 +237,11 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
return new AttributeCondition(attributeName, Operator.IsEqualTo, value);
|
return new AttributeCondition(attributeName, Operator.IsEqualTo, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Condition equals(String attributeName, int value) {
|
||||||
|
return new AttributeCondition(attributeName, Operator.IsEqualTo, String.valueOf(value));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition headerEquals(String headerName, String value) {
|
public Condition headerEquals(String headerName, String value) {
|
||||||
return new HeaderCondition(headerName, Operator.IsEqualTo, value);
|
return new HeaderCondition(headerName, Operator.IsEqualTo, value);
|
||||||
|
Loading…
Reference in New Issue
Block a user