diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java
index bca5054b..36438688 100644
--- a/src/java/davmail/exchange/dav/DavExchangeSession.java
+++ b/src/java/davmail/exchange/dav/DavExchangeSession.java
@@ -574,6 +574,8 @@ public class DavExchangeSession extends ExchangeSession {
if (value != null) {
if ("bday".equals(attributeName) || "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
value = convertDate(value);
+ } else if ("haspicture".equals(attributeName) || "private".equals(attributeName)) {
+ value = "1".equals(value)?"true":"false";
}
put(attributeName, value);
}
@@ -1223,7 +1225,7 @@ public class DavExchangeSession extends ExchangeSession {
@Override
public ExchangeSession.ContactPhoto getContactPhoto(ExchangeSession.Contact contact) throws IOException {
ContactPhoto contactPhoto = null;
- if ("1".equals(contact.get("haspicture"))) {
+ if ("true".equals(contact.get("haspicture"))) {
final GetMethod method = new GetMethod(contact.getHref() + "/ContactPicture.jpg");
method.setRequestHeader("Translate", "f");
method.setRequestHeader("Accept-Encoding", "gzip");
diff --git a/src/java/davmail/exchange/ews/DeleteAttachmentMethod.java b/src/java/davmail/exchange/ews/DeleteAttachmentMethod.java
new file mode 100644
index 00000000..6bab7572
--- /dev/null
+++ b/src/java/davmail/exchange/ews/DeleteAttachmentMethod.java
@@ -0,0 +1,34 @@
+/*
+ * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
+ * Copyright (C) 2010 Mickael Guessant
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package davmail.exchange.ews;
+
+/**
+ * Delete attachment method.
+ */
+public class DeleteAttachmentMethod extends EWSMethod {
+ /**
+ * Delete attachment method.
+ *
+ * @param attachmentId attachment id
+ */
+ public DeleteAttachmentMethod(String attachmentId) {
+ super("Item", "DeleteAttachment");
+ this.attachmentId = attachmentId;
+ }
+}
diff --git a/src/java/davmail/exchange/ews/EWSMethod.java b/src/java/davmail/exchange/ews/EWSMethod.java
index 73603fcb..e54e99c0 100644
--- a/src/java/davmail/exchange/ews/EWSMethod.java
+++ b/src/java/davmail/exchange/ews/EWSMethod.java
@@ -345,10 +345,11 @@ public abstract class EWSMethod extends PostMethod {
private void writeAttachmentId(Writer writer) throws IOException {
if (attachmentId != null) {
- writer.write("");
- writer.write("true");
- writer.write("");
-
+ if ("CreateAttachment".equals(methodName)) {
+ writer.write("");
+ writer.write("true");
+ writer.write("");
+ }
writer.write("");
writer.write(" responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, EwsExchangeSession.this.equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW);
if (!responses.isEmpty()) {
EWSMethod.Item response = responses.get(0);
currentItemId = new ItemId(response);
currentEtag = response.get(Field.get("etag").getResponseName());
+
+ // load current picture
+ GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, currentItemId, false);
+ getItemMethod.addAdditionalProperty(Field.get("attachments"));
+ executeMethod(getItemMethod);
+ EWSMethod.Item item = getItemMethod.getResponseItem();
+ if (item != null) {
+ currentFileAttachment = item.getAttachmentByName("ContactPicture.jpg");
+ }
}
if ("*".equals(noneMatch)) {
// create requested
@@ -743,14 +753,20 @@ public class EwsExchangeSession extends ExchangeSession {
//noinspection VariableNotUsedInsideIf
if (etag == null) {
itemResult.status = HttpStatus.SC_CREATED;
- LOGGER.debug("Updated event " + getHref());
+ LOGGER.debug("Created event " + getHref());
} else {
- LOGGER.warn("Overwritten event " + getHref());
+ LOGGER.warn("Updated event " + getHref());
}
}
ItemId newItemId = new ItemId(createOrUpdateItemMethod.getResponseItem());
+ // first delete current picture
+ if (currentFileAttachment != null) {
+ DeleteAttachmentMethod deleteAttachmentMethod = new DeleteAttachmentMethod(currentFileAttachment.attachmentId);
+ executeMethod(deleteAttachmentMethod);
+ }
+
if (photo != null) {
// convert image to jpeg
BufferedImage image = ImageIO.read(new ByteArrayInputStream(Base64.decodeBase64(photo.getBytes())));
diff --git a/src/java/davmail/exchange/ews/Field.java b/src/java/davmail/exchange/ews/Field.java
index 144eabe8..472900d7 100644
--- a/src/java/davmail/exchange/ews/Field.java
+++ b/src/java/davmail/exchange/ews/Field.java
@@ -135,7 +135,7 @@ public class Field {
FIELD_MAP.put("keywords", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "Keywords", ExtendedFieldURI.PropertyType.StringArray));
FIELD_MAP.put("private", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Common, 0x8506, ExtendedFieldURI.PropertyType.Boolean));
- FIELD_MAP.put("sensitivity", new ExtendedFieldURI(0x0036, ExtendedFieldURI.PropertyType.Long));
+ FIELD_MAP.put("sensitivity", new ExtendedFieldURI(0x0036, ExtendedFieldURI.PropertyType.Integer));
FIELD_MAP.put("haspicture", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Address, 0x8015, ExtendedFieldURI.PropertyType.Boolean));