mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-07 11:48:02 -05:00
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:
parent
144e86dc74
commit
325aa81ab3
@ -574,6 +574,8 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
if (value != null) {
|
if (value != null) {
|
||||||
if ("bday".equals(attributeName) || "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
|
if ("bday".equals(attributeName) || "lastmodified".equals(attributeName) || "datereceived".equals(attributeName)) {
|
||||||
value = convertDate(value);
|
value = convertDate(value);
|
||||||
|
} else if ("haspicture".equals(attributeName) || "private".equals(attributeName)) {
|
||||||
|
value = "1".equals(value)?"true":"false";
|
||||||
}
|
}
|
||||||
put(attributeName, value);
|
put(attributeName, value);
|
||||||
}
|
}
|
||||||
@ -1223,7 +1225,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
@Override
|
@Override
|
||||||
public ExchangeSession.ContactPhoto getContactPhoto(ExchangeSession.Contact contact) throws IOException {
|
public ExchangeSession.ContactPhoto getContactPhoto(ExchangeSession.Contact contact) throws IOException {
|
||||||
ContactPhoto contactPhoto = null;
|
ContactPhoto contactPhoto = null;
|
||||||
if ("1".equals(contact.get("haspicture"))) {
|
if ("true".equals(contact.get("haspicture"))) {
|
||||||
final GetMethod method = new GetMethod(contact.getHref() + "/ContactPicture.jpg");
|
final GetMethod method = new GetMethod(contact.getHref() + "/ContactPicture.jpg");
|
||||||
method.setRequestHeader("Translate", "f");
|
method.setRequestHeader("Translate", "f");
|
||||||
method.setRequestHeader("Accept-Encoding", "gzip");
|
method.setRequestHeader("Accept-Encoding", "gzip");
|
||||||
|
34
src/java/davmail/exchange/ews/DeleteAttachmentMethod.java
Normal file
34
src/java/davmail/exchange/ews/DeleteAttachmentMethod.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -345,10 +345,11 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
|
|
||||||
private void writeAttachmentId(Writer writer) throws IOException {
|
private void writeAttachmentId(Writer writer) throws IOException {
|
||||||
if (attachmentId != null) {
|
if (attachmentId != null) {
|
||||||
writer.write("<m:AttachmentShape>");
|
if ("CreateAttachment".equals(methodName)) {
|
||||||
writer.write("<t:IncludeMimeContent>true</t:IncludeMimeContent>");
|
writer.write("<m:AttachmentShape>");
|
||||||
writer.write("</m:AttachmentShape>");
|
writer.write("<t:IncludeMimeContent>true</t:IncludeMimeContent>");
|
||||||
|
writer.write("</m:AttachmentShape>");
|
||||||
|
}
|
||||||
writer.write("<m:AttachmentIds>");
|
writer.write("<m:AttachmentIds>");
|
||||||
writer.write("<t:AttachmentId Id=\"");
|
writer.write("<t:AttachmentId Id=\"");
|
||||||
writer.write(attachmentId);
|
writer.write(attachmentId);
|
||||||
@ -486,7 +487,7 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
public FileAttachment getAttachmentByName(String attachmentName) {
|
public FileAttachment getAttachmentByName(String attachmentName) {
|
||||||
FileAttachment result = null;
|
FileAttachment result = null;
|
||||||
if (attachments != null) {
|
if (attachments != null) {
|
||||||
for (FileAttachment attachment:attachments) {
|
for (FileAttachment attachment : attachments) {
|
||||||
if (attachmentName.equals(attachment.name)) {
|
if (attachmentName.equals(attachment.name)) {
|
||||||
result = attachment;
|
result = attachment;
|
||||||
break;
|
break;
|
||||||
@ -642,9 +643,9 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
if (tagLocalName.equals("AttachmentId")) {
|
if (tagLocalName.equals("AttachmentId")) {
|
||||||
fileAttachment.attachmentId = getAttributeValue(reader, "Id");
|
fileAttachment.attachmentId = getAttributeValue(reader, "Id");
|
||||||
} else if (tagLocalName.equals("Name")) {
|
} else if (tagLocalName.equals("Name")) {
|
||||||
fileAttachment.name = getTagContent(reader);
|
fileAttachment.name = getTagContent(reader);
|
||||||
} else if (tagLocalName.equals("ContentType")) {
|
} else if (tagLocalName.equals("ContentType")) {
|
||||||
fileAttachment.contentType = getTagContent(reader);
|
fileAttachment.contentType = getTagContent(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -703,11 +703,21 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
String urlcompname = convertItemNameToEML(itemName);
|
String urlcompname = convertItemNameToEML(itemName);
|
||||||
String currentEtag = null;
|
String currentEtag = null;
|
||||||
ItemId currentItemId = null;
|
ItemId currentItemId = null;
|
||||||
|
FileAttachment currentFileAttachment = null;
|
||||||
List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, EwsExchangeSession.this.equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW);
|
List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, EwsExchangeSession.this.equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW);
|
||||||
if (!responses.isEmpty()) {
|
if (!responses.isEmpty()) {
|
||||||
EWSMethod.Item response = responses.get(0);
|
EWSMethod.Item response = responses.get(0);
|
||||||
currentItemId = new ItemId(response);
|
currentItemId = new ItemId(response);
|
||||||
currentEtag = response.get(Field.get("etag").getResponseName());
|
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)) {
|
if ("*".equals(noneMatch)) {
|
||||||
// create requested
|
// create requested
|
||||||
@ -743,14 +753,20 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
//noinspection VariableNotUsedInsideIf
|
//noinspection VariableNotUsedInsideIf
|
||||||
if (etag == null) {
|
if (etag == null) {
|
||||||
itemResult.status = HttpStatus.SC_CREATED;
|
itemResult.status = HttpStatus.SC_CREATED;
|
||||||
LOGGER.debug("Updated event " + getHref());
|
LOGGER.debug("Created event " + getHref());
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("Overwritten event " + getHref());
|
LOGGER.warn("Updated event " + getHref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemId newItemId = new ItemId(createOrUpdateItemMethod.getResponseItem());
|
ItemId newItemId = new ItemId(createOrUpdateItemMethod.getResponseItem());
|
||||||
|
|
||||||
|
// first delete current picture
|
||||||
|
if (currentFileAttachment != null) {
|
||||||
|
DeleteAttachmentMethod deleteAttachmentMethod = new DeleteAttachmentMethod(currentFileAttachment.attachmentId);
|
||||||
|
executeMethod(deleteAttachmentMethod);
|
||||||
|
}
|
||||||
|
|
||||||
if (photo != null) {
|
if (photo != null) {
|
||||||
// convert image to jpeg
|
// convert image to jpeg
|
||||||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(Base64.decodeBase64(photo.getBytes())));
|
BufferedImage image = ImageIO.read(new ByteArrayInputStream(Base64.decodeBase64(photo.getBytes())));
|
||||||
|
@ -135,7 +135,7 @@ public class Field {
|
|||||||
FIELD_MAP.put("keywords", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "Keywords", ExtendedFieldURI.PropertyType.StringArray));
|
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("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));
|
FIELD_MAP.put("haspicture", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.Address, 0x8015, ExtendedFieldURI.PropertyType.Boolean));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user