From 9a701c638568d001fd150ce559fe2f14dc826340 Mon Sep 17 00:00:00 2001 From: mguessan Date: Sun, 18 Jul 2010 21:33:22 +0000 Subject: [PATCH] Carddav: fix boolean field handling git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1194 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 7 +-- .../exchange/dav/DavExchangeSession.java | 5 +- src/java/davmail/exchange/dav/Field.java | 52 +++++++++++-------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 45743672..60e943b3 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -2800,10 +2800,10 @@ public abstract class ExchangeSession { } else if ("CLASS".equals(property.getKey())) { if ("PUBLIC".equals(property.getValue())) { properties.put("sensitivity", "0"); - properties.put("private", "0"); + properties.put("private", "false"); } else { properties.put("sensitivity", "2"); - properties.put("private", "1"); + properties.put("private", "true"); } } else if ("X-ASSISTANT".equals(property.getKey())) { properties.put("secretarycn", property.getValue()); @@ -2819,7 +2819,8 @@ public abstract class ExchangeSession { for (String key : CONTACT_ATTRIBUTES) { if (!"imapUid".equals(key) && !"etag".equals(key) && !"urlcompname".equals(key) && !properties.containsKey(key)) { - properties.put(key, null); +// TODO: enable + //properties.put(key, null); } } diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index c98f852b..2cf4912a 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -673,7 +673,7 @@ public class DavExchangeSession extends ExchangeSession { } ArrayList changeList = new ArrayList(); - changeList.add(Field.createDavProperty("attachmentContactPhoto", "1")); + changeList.add(Field.createDavProperty("attachmentContactPhoto", "true")); changeList.add(Field.createDavProperty("renderingPosition", "-1")); final PropPatchMethod attachmentPropPatchMethod = new PropPatchMethod(contactPictureUrl, changeList); @@ -1210,7 +1210,8 @@ public class DavExchangeSession extends ExchangeSession { @Override public ExchangeSession.ContactPhoto getContactPhoto(ExchangeSession.Contact contact) throws IOException { ContactPhoto contactPhoto; - final GetMethod method = new GetMethod(getFolderPath(CONTACTS) + '/' + contact.get("urlcompname") + "/ContactPicture.jpg"); + final GetMethod method = new GetMethod(contact.getHref() + "/ContactPicture.jpg"); + method.setRequestHeader("Translate", "f"); method.setRequestHeader("Accept-Encoding", "gzip"); try { diff --git a/src/java/davmail/exchange/dav/Field.java b/src/java/davmail/exchange/dav/Field.java index 91e768b2..b543bdef 100644 --- a/src/java/davmail/exchange/dav/Field.java +++ b/src/java/davmail/exchange/dav/Field.java @@ -250,8 +250,8 @@ public class Field { //createField("keywords", DistinguishedPropertySetType.PublicStrings, "Keywords", ); // PS_PUBLIC_STRINGS Keywords String // contact private flags - createField("private", DistinguishedPropertySetType.Common, 0x8506, "private"); // True/False - createField("writeprivate", DistinguishedPropertySetType.Common, 0x8506, PropertyType.String10); + createField("private", DistinguishedPropertySetType.Common, 0x8506, "private", PropertyType.Boolean); // True/False + createField("writeprivate", DistinguishedPropertySetType.Common, 0x8506, PropertyType.Boolean); createField("sensitivity", 0x0036, PropertyType.Long); // PR_SENSITIVITY SENSITIVITY_PRIVATE = 2, SENSITIVITY_PERSONAL = 1, SENSITIVITY_NONE = 0 createField("haspicture", DistinguishedPropertySetType.Address, 0x8015, "haspicture"); // True/False @@ -279,17 +279,18 @@ public class Field { String name = 'x' + toHexString(propertyTag) + propertyTypeMap.get(propertyType); Field field; if (propertyType == PropertyType.Binary) { - field = new Field(alias, SCHEMAS_MAPI_PROPTAG, name, null, "bin.base64"); + field = new Field(alias, SCHEMAS_MAPI_PROPTAG, name, null, "bin.base64", propertyType); } else { - field = new Field(alias, SCHEMAS_MAPI_PROPTAG, name); - } - if (propertyType == PropertyType.Integer || propertyType == PropertyType.Long) { - field.isIntValue = true; + field = new Field(alias, SCHEMAS_MAPI_PROPTAG, name, propertyType); } fieldMap.put(field.alias, field); } protected static void createField(String alias, DistinguishedPropertySetType propertySetType, int propertyTag, String responseAlias) { + createField(alias, propertySetType, propertyTag, responseAlias, null); + } + + protected static void createField(String alias, DistinguishedPropertySetType propertySetType, int propertyTag, String responseAlias, PropertyType propertyType) { String name; if (propertySetType == DistinguishedPropertySetType.Address) { // Address namespace expects integer names @@ -299,15 +300,15 @@ public class Field { name = "0x" + toHexString(propertyTag); } Field field = new Field(alias, Namespace.getNamespace(SCHEMAS_MAPI_ID.getURI() + - '{' + distinguishedPropertySetMap.get(propertySetType) + "}/"), name, responseAlias, null); + '{' + distinguishedPropertySetMap.get(propertySetType) + "}/"), name, responseAlias, null, propertyType); fieldMap.put(field.alias, field); } protected static void createField(String alias, DistinguishedPropertySetType propertySetType, int propertyTag, PropertyType propertyType) { - String name = "_x" + propertyTypeMap.get(propertyType) + "_x" + toHexString(propertyTag); + String name = "_x0030_x" + toHexString(propertyTag); Field field = new Field(alias, Namespace.getNamespace(SCHEMAS_MAPI_ID.getURI() + - '{' + distinguishedPropertySetMap.get(propertySetType) + "}/"), name); + '{' + distinguishedPropertySetMap.get(propertySetType) + "}/"), name, propertyType); fieldMap.put(field.alias, field); } @@ -317,38 +318,41 @@ public class Field { } protected static void createField(String alias, Namespace namespace, String name) { - Field field = new Field(alias, namespace, name); + Field field = new Field(alias, namespace, name, null); fieldMap.put(field.alias, field); } protected static void createField(String alias, Namespace namespace, String name, PropertyType propertyType) { - Field field = new Field(alias, namespace, name); - if (propertyType == PropertyType.StringArray) { - field.isMultivalued = true; - } + Field field = new Field(alias, namespace, name, propertyType); fieldMap.put(field.alias, field); } protected final DavPropertyName davPropertyName; + protected final PropertyType propertyType; protected final String alias; protected final String uri; protected final String requestPropertyString; protected final DavPropertyName responsePropertyName; protected final String cast; - protected boolean isIntValue; - protected boolean isMultivalued; + protected final boolean isIntValue; + protected final boolean isMultivalued; + protected final boolean isBooleanValue; public Field(Namespace namespace, String name) { - this(name, namespace, name); + this(name, namespace, name, null); } - public Field(String alias, Namespace namespace, String name) { - this(alias, namespace, name, null, null); + public Field(String alias, Namespace namespace, String name, PropertyType propertyType) { + this(alias, namespace, name, null, null, propertyType); } - public Field(String alias, Namespace namespace, String name, String responseAlias, String cast) { + public Field(String alias, Namespace namespace, String name, String responseAlias, String cast, PropertyType propertyType) { davPropertyName = DavPropertyName.create(name, namespace); + this.propertyType = propertyType; + isMultivalued = propertyType == PropertyType.StringArray; + isIntValue = propertyType == PropertyType.Integer || propertyType == PropertyType.Long; + isBooleanValue = propertyType == PropertyType.Boolean; this.alias = alias; this.uri = namespace.getURI() + name; if (responseAlias == null) { @@ -414,6 +418,12 @@ public class Field { } return new DefaultDavProperty(field.davPropertyName, valueList); + } else if (field.isBooleanValue) { + if ("true".equals(value)) { + return new DefaultDavProperty(field.davPropertyName, "1"); + } else { + return new DefaultDavProperty(field.davPropertyName, "0"); + } } else { return new DefaultDavProperty(field.davPropertyName, value); }