mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 03:02:22 -05:00
EWS: dynamic version detection
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1299 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
a1916248d6
commit
875e7894ff
@ -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("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
|
||||
"xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" " +
|
||||
"xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\">" +
|
||||
"<soap:Header>" +
|
||||
"<t:RequestServerVersion Version=\"Exchange2007_SP1\"/>" +
|
||||
"</soap:Header>" +
|
||||
"<soap:Body>");
|
||||
"");
|
||||
if (serverVersion != null) {
|
||||
writer.write("<soap:Header><t:RequestServerVersion Version=\"");
|
||||
writer.write(serverVersion);
|
||||
writer.write("\"/></soap:Header>");
|
||||
}
|
||||
|
||||
writer.write("<soap:Body>");
|
||||
writer.write("<m:");
|
||||
writer.write(methodName);
|
||||
if (traversal != null) {
|
||||
@ -380,6 +385,22 @@ public abstract class EWSMethod extends PostMethod {
|
||||
return inputFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Exchange server version, Exchange2010 or Exchange2007_SP1
|
||||
* @return server version
|
||||
*/
|
||||
public String getServerVersion() {
|
||||
return serverVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Exchange server version, Exchange2010 or Exchange2007_SP1
|
||||
* @param serverVersion server version
|
||||
*/
|
||||
public void setServerVersion(String serverVersion) {
|
||||
this.serverVersion = serverVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Item
|
||||
*/
|
||||
@ -619,6 +640,7 @@ public abstract class EWSMethod extends PostMethod {
|
||||
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||
String tagLocalName = reader.getLocalName();
|
||||
String value = null;
|
||||
// detect version
|
||||
if ("ExtendedProperty".equals(tagLocalName)) {
|
||||
addExtendedPropertyValue(reader, responseItem);
|
||||
} else if (tagLocalName.endsWith("MimeContent")) {
|
||||
@ -757,7 +779,14 @@ public abstract class EWSMethod extends PostMethod {
|
||||
while (reader.hasNext()) {
|
||||
reader.next();
|
||||
handleErrors(reader);
|
||||
if (isStartTag(reader, responseCollectionName)) {
|
||||
if (serverVersion == null && isStartTag(reader,"ServerVersionInfo")) {
|
||||
String majorVersion = getAttributeValue(reader, "MajorVersion");
|
||||
if ("14".equals(majorVersion)) {
|
||||
serverVersion = "Exchange2010";
|
||||
} else {
|
||||
serverVersion = "Exchange2007_SP1";
|
||||
}
|
||||
} else if (isStartTag(reader, responseCollectionName)) {
|
||||
handleItems(reader);
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import java.util.*;
|
||||
public class EwsExchangeSession extends ExchangeSession {
|
||||
|
||||
protected Map<String, String> 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();
|
||||
|
@ -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("</t:ContentType>");
|
||||
}
|
||||
if (isContactPhoto) {
|
||||
writer.write("<t:IsContactPhoto>true</t:IsContactPhoto>");
|
||||
}
|
||||
if (content != null) {
|
||||
writer.write("<t:Content>");
|
||||
writer.write(content);
|
||||
@ -66,4 +70,8 @@ public class FileAttachment {
|
||||
writer.write("</t:FileAttachment>");
|
||||
}
|
||||
|
||||
public void setIsContactPhoto(boolean isContactPhoto) {
|
||||
this.isContactPhoto = isContactPhoto;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user