From 875e7894ffbb2307addf56e82120b5dbbb7c9ff7 Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 27 Jul 2010 12:58:23 +0000 Subject: [PATCH] EWS: dynamic version detection git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1299 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/exchange/ews/EWSMethod.java | 41 ++++++++++++++++--- .../exchange/ews/EwsExchangeSession.java | 9 +++- .../davmail/exchange/ews/FileAttachment.java | 8 ++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/java/davmail/exchange/ews/EWSMethod.java b/src/java/davmail/exchange/ews/EWSMethod.java index 98877303..559c5fcf 100644 --- a/src/java/davmail/exchange/ews/EWSMethod.java +++ b/src/java/davmail/exchange/ews/EWSMethod.java @@ -70,6 +70,7 @@ public abstract class EWSMethod extends PostMethod { protected SearchExpression searchExpression; + protected String serverVersion; /** * Build EWS method @@ -104,7 +105,7 @@ public abstract class EWSMethod extends PostMethod { } public String getContentType() { - return "text/xml;charset=UTF-8"; + return "text/xml; charset=UTF-8"; } }); } @@ -297,10 +298,14 @@ public abstract class EWSMethod extends PostMethod { writer.write("" + - "" + - "" + - "" + - ""); + ""); + if (serverVersion != null) { + writer.write(""); + } + + writer.write(""); writer.write(" folderIdMap; + protected String serverVersion; protected class Folder extends ExchangeSession.Folder { public FolderId folderId; @@ -782,8 +783,10 @@ public class EwsExchangeSession extends ExchangeSession { // convert image to jpeg byte[] resizedImageBytes = IOUtil.resizeImage(Base64.decodeBase64(photo.getBytes()), 90); - // TODO: handle photo update, fix attachment mapi properties (available only with Exchange 2010) FileAttachment attachment = new FileAttachment("ContactPicture.jpg", "image/jpeg", new String(Base64.encodeBase64(resizedImageBytes))); + if ("Exchange2010".equals(serverVersion)) { + attachment.setIsContactPhoto(true); + } // update photo attachment CreateAttachmentMethod createAttachmentMethod = new CreateAttachmentMethod(newItemId, attachment); executeMethod(createAttachmentMethod); @@ -1131,7 +1134,11 @@ public class EwsExchangeSession extends ExchangeSession { protected void executeMethod(EWSMethod ewsMethod) throws IOException { try { + ewsMethod.setServerVersion(serverVersion); httpClient.executeMethod(ewsMethod); + if (serverVersion == null) { + serverVersion = ewsMethod.getServerVersion(); + } ewsMethod.checkSuccess(); } finally { ewsMethod.releaseConnection(); diff --git a/src/java/davmail/exchange/ews/FileAttachment.java b/src/java/davmail/exchange/ews/FileAttachment.java index a4cf8160..423fbde9 100644 --- a/src/java/davmail/exchange/ews/FileAttachment.java +++ b/src/java/davmail/exchange/ews/FileAttachment.java @@ -29,6 +29,7 @@ public class FileAttachment { protected String contentType; protected String content; protected String attachmentId; + protected boolean isContactPhoto; public FileAttachment() { // empty constructor @@ -58,6 +59,9 @@ public class FileAttachment { writer.write(contentType); writer.write(""); } + if (isContactPhoto) { + writer.write("true"); + } if (content != null) { writer.write(""); writer.write(content); @@ -66,4 +70,8 @@ public class FileAttachment { writer.write(""); } + public void setIsContactPhoto(boolean isContactPhoto) { + this.isContactPhoto = isContactPhoto; + } + }