From f1075c57e7af5d4c1b6ad561cb06254ea04960f3 Mon Sep 17 00:00:00 2001 From: mguessan Date: Sun, 18 Jul 2010 12:26:12 +0000 Subject: [PATCH] Carddav: implement CLASS (private) flag git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1191 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 16 ++++++++++++- .../exchange/dav/DavExchangeSession.java | 23 +++++++++---------- src/java/davmail/exchange/dav/Field.java | 3 ++- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 5d73f8e8..1c13b930 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -1751,9 +1751,12 @@ public abstract class ExchangeSession { writer.appendProperty("BDAY", get("bday")); - // categories writer.appendProperty("CATEGORIES", get("keywords")); + if ("1".equals(get("private"))) { + writer.appendProperty("CLASS", "PRIVATE"); + } + writer.appendProperty("X-ASSISTANT", get("secretarycn")); writer.appendProperty("X-MANAGER", get("manager")); writer.appendProperty("X-SPOUSE", get("spousecn")); @@ -2770,6 +2773,14 @@ public abstract class ExchangeSession { } } else if ("CATEGORIES".equals(property.getKey())) { properties.put("keywords", property.getValue()); + } else if ("CLASS".equals(property.getKey())) { + if ("PUBLIC".equals(property.getValue())) { + properties.put("sensitivity", "0"); + properties.put("private", "0"); + } else { + properties.put("sensitivity", "2"); + properties.put("private", "1"); + } } else if ("X-ASSISTANT".equals(property.getKey())) { properties.put("secretarycn", property.getValue()); } else if ("X-MANAGER".equals(property.getKey())) { @@ -3133,6 +3144,9 @@ public abstract class ExchangeSession { CONTACT_ATTRIBUTES.add("othercity"); CONTACT_ATTRIBUTES.add("haspicture"); CONTACT_ATTRIBUTES.add("keywords"); + + CONTACT_ATTRIBUTES.add("private"); + CONTACT_ATTRIBUTES.add("sensitivity"); } /** diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 6bcc2063..22f8dfbe 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -590,7 +590,7 @@ public class DavExchangeSession extends ExchangeSession { ArrayList list = new ArrayList(); for (Map.Entry entry : entrySet()) { String key = entry.getKey(); - if (key.startsWith("email")) { + if (key.startsWith("email") || key.equals("private")) { key = "write" + key; } if (!"photo".equals(key)) { @@ -609,7 +609,12 @@ public class DavExchangeSession extends ExchangeSession { */ public ItemResult createOrUpdate() throws IOException { int status = 0; - PropPatchMethod propPatchMethod = new PropPatchMethod(URIUtil.encodePath(getHref()), buildProperties()); + PropPatchMethod propPatchMethod = new PropPatchMethod(URIUtil.encodePath(getHref()), buildProperties()) { + @Override + protected void processResponseBody(HttpState httpState, HttpConnection httpConnection) { + // ignore response body, sometimes invalid with exchange mapi properties + } + }; propPatchMethod.setRequestHeader("Translate", "f"); if (etag != null) { propPatchMethod.setRequestHeader("If-Match", etag); @@ -620,22 +625,16 @@ public class DavExchangeSession extends ExchangeSession { try { status = httpClient.executeMethod(propPatchMethod); if (status == HttpStatus.SC_MULTI_STATUS) { - MultiStatus responses = propPatchMethod.getResponseBodyAsMultiStatus(); - if (responses.getResponses().length > 0) { - status = responses.getResponses()[0].getStatus()[0].getStatusCode(); - } - - if (status == HttpStatus.SC_CREATED) { + if (etag == null) { + status = HttpStatus.SC_CREATED; LOGGER.debug("Created contact " + getHref()); } else { + status = HttpStatus.SC_OK; LOGGER.debug("Updated contact " + getHref()); } } else { LOGGER.warn("Unable to create or update contact " + status + ' ' + propPatchMethod.getStatusLine()); - } - } catch (DavException e) { - LOGGER.error("Error in item create or update", e); - throw new IOException(e); + } } finally { propPatchMethod.releaseConnection(); } diff --git a/src/java/davmail/exchange/dav/Field.java b/src/java/davmail/exchange/dav/Field.java index fb116898..91e768b2 100644 --- a/src/java/davmail/exchange/dav/Field.java +++ b/src/java/davmail/exchange/dav/Field.java @@ -251,7 +251,8 @@ public class Field { // contact private flags createField("private", DistinguishedPropertySetType.Common, 0x8506, "private"); // True/False - createField("sensitivity", 0x0036, PropertyType.Long); // PR_SENSITIVITY SENSITIVITY_PRIVATE=2, SENSITIVITY_NONE = 0 + createField("writeprivate", DistinguishedPropertySetType.Common, 0x8506, PropertyType.String10); + createField("sensitivity", 0x0036, PropertyType.Long); // PR_SENSITIVITY SENSITIVITY_PRIVATE = 2, SENSITIVITY_PERSONAL = 1, SENSITIVITY_NONE = 0 createField("haspicture", DistinguishedPropertySetType.Address, 0x8015, "haspicture"); // True/False