From 2b9d0061c0133bc30528e205851aee9ddc2d79fd Mon Sep 17 00:00:00 2001 From: mguessan Date: Wed, 16 Jun 2010 12:06:59 +0000 Subject: [PATCH] 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 --- .../davmail/exchange/ExchangeSession.java | 8 ++-- .../exchange/dav/DavExchangeSession.java | 48 +++++++++++++------ src/java/davmail/exchange/dav/Field.java | 28 +++++++++-- .../exchange/ews/EwsExchangeSession.java | 5 ++ 4 files changed, 68 insertions(+), 21 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 2b247d10..f5bf84b2 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -742,6 +742,8 @@ public abstract class ExchangeSession { 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 gte(String attributeName, String value); @@ -2586,7 +2588,7 @@ public abstract class ExchangeSession { public List getEventMessages(String folderPath) throws IOException { return searchEvents(folderPath, ITEM_PROPERTIES, 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, and(or(isNull("instancetype"), - equals("instancetype", "1"), - and(equals("instancetype", "0"), dateCondition)), + equals("instancetype", 1), + and(equals("instancetype", 0), dateCondition)), equals("contentclass", "urn:content-classes:appointment"), privateCondition)); } diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index f5db5c5e..bb161ba4 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -272,19 +272,29 @@ public class DavExchangeSession extends ExchangeSession { operatorMap.put(Operator.IsLessThan, " < "); operatorMap.put(Operator.Like, " like "); 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 boolean isIntValue = false; + protected AttributeCondition(String attributeName, Operator operator, String value) { super(attributeName, operator, value); } + protected AttributeCondition(String attributeName, Operator operator, int value) { + super(attributeName, operator, String.valueOf(value)); + isIntValue = true; + } + @Override public void appendTo(StringBuilder buffer) { buffer.append('"').append(Field.get(attributeName).getUri()).append('"'); buffer.append(operatorMap.get(operator)); - buffer.append('\''); + if (!isIntValue) { + buffer.append('\''); + } if (Operator.Like == operator) { buffer.append('%'); } @@ -292,7 +302,9 @@ public class DavExchangeSession extends ExchangeSession { if (Operator.Like == operator) { buffer.append('%'); } - buffer.append('\''); + if (!isIntValue) { + buffer.append('\''); + } } } @@ -354,6 +366,11 @@ public class DavExchangeSession extends ExchangeSession { return new AttributeCondition(attributeName, Operator.IsEqualTo, value); } + @Override + public Condition equals(String attributeName, int value) { + return new AttributeCondition(attributeName, Operator.IsEqualTo, value); + } + @Override public Condition headerEquals(String headerName, String value) { return new HeaderCondition(headerName, Operator.IsEqualTo, value); @@ -428,9 +445,9 @@ public class DavExchangeSession extends ExchangeSession { public Event(MultiStatusResponse multiStatusResponse) throws URIException { href = URIUtil.decode(multiStatusResponse.getHref()); DavPropertySet properties = multiStatusResponse.getProperties(HttpStatus.SC_OK); - permanentUrl = getPropertyIfExists(properties, "permanenturl", SCHEMAS_EXCHANGE); - etag = getPropertyIfExists(properties, "getetag", DAV); - displayName = getPropertyIfExists(properties, "displayname", DAV); + permanentUrl = getPropertyIfExists(properties, "permanenturl"); + etag = getPropertyIfExists(properties, "etag"); + displayName = getPropertyIfExists(properties, "displayname"); } 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) { - DavProperty property = properties.get(name, EMPTY); + protected String getPropertyIfExists(DavPropertySet properties, String alias) { + DavProperty property = properties.get(Field.getResponsePropertyName(alias)); if (property == null) { return null; } else { @@ -660,8 +677,8 @@ public class DavExchangeSession extends ExchangeSession { } } - protected int getIntPropertyIfExists(DavPropertySet properties, String name) { - DavProperty property = properties.get(name, EMPTY); + protected int getIntPropertyIfExists(DavPropertySet properties, String alias) { + DavProperty property = properties.get(Field.getResponsePropertyName(alias)); if (property == null) { return 0; } else { @@ -669,8 +686,8 @@ public class DavExchangeSession extends ExchangeSession { } } - protected long getLongPropertyIfExists(DavPropertySet properties, String name) { - DavProperty property = properties.get(name, EMPTY); + protected long getLongPropertyIfExists(DavPropertySet properties, String alias) { + DavProperty property = properties.get(Field.getResponsePropertyName(alias)); if (property == null) { return 0; } else { @@ -768,14 +785,15 @@ public class DavExchangeSession extends ExchangeSession { public MultiStatusResponse[] searchItems(String folderName, List attributes, Condition condition) throws IOException { String folderUrl = getFolderPath(folderName); 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) { for (String attribute : attributes) { 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"); if (condition != null) { searchRequest.append(" AND "); diff --git a/src/java/davmail/exchange/dav/Field.java b/src/java/davmail/exchange/dav/Field.java index 36a486a4..75698d83 100644 --- a/src/java/davmail/exchange/dav/Field.java +++ b/src/java/davmail/exchange/dav/Field.java @@ -61,6 +61,9 @@ public class Field { '{' + distinguishedPropertySetMap.get(DistinguishedPropertySetType.InternetHeaders) + "}/"); + /** + * Property type list from EWS + */ protected static enum PropertyType { ApplicationTime, ApplicationTimeArray, Binary, BinaryArray, Boolean, CLSID, CLSIDArray, Currency, CurrencyArray, 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(URN_SCHEMAS_HTTPMAIL, "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); // http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/0x8506 private createField(URN_SCHEMAS_HTTPMAIL, "date");//PR_CLIENT_SUBMIT_TIME, 0x0039 @@ -158,9 +161,9 @@ public class 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); - Field field = new Field(alias, SCHEMAS_MAPI_ID, name); + Field field = new Field(alias, SCHEMAS_MAPI_ID, name, responseAlias); fieldMap.put(field.alias, field); } @@ -185,15 +188,25 @@ public class Field { protected final DavPropertyName davPropertyName; protected final String alias; protected final String uri; + protected final String requestPropertyString; public Field(Namespace namespace, String name) { this(name, namespace, 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); this.alias = alias; this.uri = namespace.getURI() + name; + if (responseAlias == null) { + this.requestPropertyString = '"' + uri + '"'; + } else { + this.requestPropertyString = '"' + uri + "\" as " + responseAlias; + } } public String getUri() { @@ -236,4 +249,13 @@ public class Field { 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; + } } diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index 10277a18..c9269868 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -237,6 +237,11 @@ public class EwsExchangeSession extends ExchangeSession { 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 public Condition headerEquals(String headerName, String value) { return new HeaderCondition(headerName, Operator.IsEqualTo, value);