Carddav: Implement picture delete and private flag over EWS

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1196 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-18 23:36:25 +00:00
parent 144e86dc74
commit 325aa81ab3
5 changed files with 64 additions and 11 deletions

View File

@ -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");

View File

@ -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;
}
}

View File

@ -345,10 +345,11 @@ public abstract class EWSMethod extends PostMethod {
private void writeAttachmentId(Writer writer) throws IOException {
if (attachmentId != null) {
writer.write("<m:AttachmentShape>");
writer.write("<t:IncludeMimeContent>true</t:IncludeMimeContent>");
writer.write("</m:AttachmentShape>");
if ("CreateAttachment".equals(methodName)) {
writer.write("<m:AttachmentShape>");
writer.write("<t:IncludeMimeContent>true</t:IncludeMimeContent>");
writer.write("</m:AttachmentShape>");
}
writer.write("<m:AttachmentIds>");
writer.write("<t:AttachmentId Id=\"");
writer.write(attachmentId);
@ -486,7 +487,7 @@ public abstract class EWSMethod extends PostMethod {
public FileAttachment getAttachmentByName(String attachmentName) {
FileAttachment result = null;
if (attachments != null) {
for (FileAttachment attachment:attachments) {
for (FileAttachment attachment : attachments) {
if (attachmentName.equals(attachment.name)) {
result = attachment;
break;
@ -642,9 +643,9 @@ public abstract class EWSMethod extends PostMethod {
if (tagLocalName.equals("AttachmentId")) {
fileAttachment.attachmentId = getAttributeValue(reader, "Id");
} else if (tagLocalName.equals("Name")) {
fileAttachment.name = getTagContent(reader);
fileAttachment.name = getTagContent(reader);
} else if (tagLocalName.equals("ContentType")) {
fileAttachment.contentType = getTagContent(reader);
fileAttachment.contentType = getTagContent(reader);
}
}
}

View File

@ -703,11 +703,21 @@ public class EwsExchangeSession extends ExchangeSession {
String urlcompname = convertItemNameToEML(itemName);
String currentEtag = null;
ItemId currentItemId = null;
FileAttachment currentFileAttachment = null;
List<EWSMethod.Item> 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())));

View File

@ -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));