1
0
mirror of https://github.com/moparisthebest/davmail synced 2025-01-07 11:48:02 -05:00

Caldav: move processItem logic back to CaldavConnection

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1149 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-07 12:55:13 +00:00
parent 90df0e2fdf
commit 944da102e3
6 changed files with 86 additions and 26 deletions

View File

@ -272,7 +272,12 @@ public class CaldavConnection extends AbstractConnection {
sendHttpResponse(itemResult.status, buildEtagHeader(itemResult.etag), null, "", true); sendHttpResponse(itemResult.status, buildEtagHeader(itemResult.etag), null, "", true);
} else if (request.isDelete()) { } else if (request.isDelete()) {
int status = session.deleteItem(request.getFolderPath(), lastPath); int status;
if (request.getFolderPath().endsWith("inbox")) {
status = session.processItem(request.getFolderPath(), lastPath);
} else {
status = session.deleteItem(request.getFolderPath(), lastPath);
}
sendHttpResponse(status); sendHttpResponse(status);
} else if (request.isGet()) { } else if (request.isGet()) {
if (request.path.endsWith("/")) { if (request.path.endsWith("/")) {

View File

@ -2598,6 +2598,7 @@ public abstract class ExchangeSession {
/** /**
* Retrieve contact photo attached to contact * Retrieve contact photo attached to contact
*
* @param contact address book contact * @param contact address book contact
* @return contact photo * @return contact photo
* @throws IOException on error * @throws IOException on error
@ -2606,15 +2607,26 @@ public abstract class ExchangeSession {
/** /**
* Delete event named eventName in folder * Delete event named itemName in folder
* *
* @param folderPath Exchange folder path * @param folderPath Exchange folder path
* @param itemName event name * @param itemName item name
* @return HTTP status * @return HTTP status
* @throws IOException on error * @throws IOException on error
*/ */
public abstract int deleteItem(String folderPath, String itemName) throws IOException; public abstract int deleteItem(String folderPath, String itemName) throws IOException;
/**
* Mark event processed named eventName in folder
*
* @param folderPath Exchange folder path
* @param itemName item name
* @return HTTP status
* @throws IOException on error
*/
public abstract int processItem(String folderPath, String itemName) throws IOException;
private static int dumpIndex; private static int dumpIndex;
/** /**

View File

@ -1206,19 +1206,19 @@ public class DavExchangeSession extends ExchangeSession {
@Override @Override
public int deleteItem(String folderPath, String itemName) throws IOException { public int deleteItem(String folderPath, String itemName) throws IOException {
String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName)); String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName));
int status; return DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath);
if (inboxUrl.endsWith(folderPath)) { }
// do not delete calendar messages, mark read and processed
ArrayList<DavConstants> list = new ArrayList<DavConstants>(); @Override
list.add(Field.createDavProperty("processed", "1")); public int processItem(String folderPath, String itemName) throws IOException {
list.add(Field.createDavProperty("read", "1")); String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName));
PropPatchMethod patchMethod = new PropPatchMethod(eventPath, list); // do not delete calendar messages, mark read and processed
DavGatewayHttpClientFacade.executeMethod(httpClient, patchMethod); ArrayList<DavConstants> list = new ArrayList<DavConstants>();
status = HttpStatus.SC_OK; list.add(Field.createDavProperty("processed", "1"));
} else { list.add(Field.createDavProperty("read", "1"));
status = DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath); PropPatchMethod patchMethod = new PropPatchMethod(eventPath, list);
} DavGatewayHttpClientFacade.executeMethod(httpClient, patchMethod);
return status; return HttpStatus.SC_OK;
} }
/** /**

View File

@ -186,7 +186,7 @@ public class EwsExchangeSession extends ExchangeSession {
executeMethod(createItemMethod); executeMethod(createItemMethod);
if (bcc != null) { if (bcc != null) {
ItemId itemId = new ItemId(createItemMethod.getResponseItem().get("ItemId"), createItemMethod.getResponseItem().get("ChangeKey")); ItemId itemId = new ItemId(createItemMethod.getResponseItem());
HashMap<String, String> localProperties = new HashMap<String, String>(); HashMap<String, String> localProperties = new HashMap<String, String>();
localProperties.put("bcc", bcc); localProperties.put("bcc", bcc);
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly, UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
@ -249,7 +249,7 @@ public class EwsExchangeSession extends ExchangeSession {
Message message = new Message(); Message message = new Message();
// get item id // get item id
message.itemId = new ItemId(response.get("ItemId"), response.get("ChangeKey")); message.itemId = new ItemId(response);
message.permanentUrl = response.get(Field.get("permanenturl").getResponseName()); message.permanentUrl = response.get(Field.get("permanenturl").getResponseName());
@ -506,7 +506,7 @@ public class EwsExchangeSession extends ExchangeSession {
protected Folder buildFolder(EWSMethod.Item item) { protected Folder buildFolder(EWSMethod.Item item) {
Folder folder = new Folder(); Folder folder = new Folder();
folder.folderId = new FolderId(item.get("FolderId"), item.get("ChangeKey")); folder.folderId = new FolderId(item);
folder.displayName = item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getResponseName()); folder.displayName = item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getResponseName());
folder.folderClass = item.get(ExtendedFieldURI.PR_CONTAINER_CLASS.getResponseName()); folder.folderClass = item.get(ExtendedFieldURI.PR_CONTAINER_CLASS.getResponseName());
folder.etag = item.get(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME.getResponseName()); folder.etag = item.get(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME.getResponseName());
@ -651,7 +651,7 @@ public class EwsExchangeSession extends ExchangeSession {
ItemId itemId; ItemId itemId;
protected Contact(EWSMethod.Item response) throws URIException { protected Contact(EWSMethod.Item response) throws URIException {
itemId = new ItemId(response.get("ItemId"), response.get("ChangeKey")); itemId = new ItemId(response);
permanentUrl = response.get(Field.get("permanenturl").getResponseName()); permanentUrl = response.get(Field.get("permanenturl").getResponseName());
etag = response.get(Field.get("etag").getResponseName()); etag = response.get(Field.get("etag").getResponseName());
@ -729,7 +729,7 @@ public class EwsExchangeSession extends ExchangeSession {
ItemId itemId; ItemId itemId;
protected Event(EWSMethod.Item response) throws URIException { protected Event(EWSMethod.Item response) throws URIException {
itemId = new ItemId(response.get("ItemId"), response.get("ChangeKey")); itemId = new ItemId(response);
permanentUrl = response.get(Field.get("permanenturl").getResponseName()); permanentUrl = response.get(Field.get("permanenturl").getResponseName());
etag = response.get(Field.get("etag").getResponseName()); etag = response.get(Field.get("etag").getResponseName());
@ -742,7 +742,7 @@ public class EwsExchangeSession extends ExchangeSession {
public Event(String folderPath, String itemName, String contentClass, String itemBody, String etag, String noneMatch) { public Event(String folderPath, String itemName, String contentClass, String itemBody, String etag, String noneMatch) {
super(folderPath, itemName, contentClass, itemBody, etag, noneMatch); super(folderPath, itemName, contentClass, itemBody, etag, noneMatch);
} }
@Override @Override
protected ItemResult createOrUpdate(byte[] content) throws IOException { protected ItemResult createOrUpdate(byte[] content) throws IOException {
@ -848,7 +848,30 @@ public class EwsExchangeSession extends ExchangeSession {
@Override @Override
public int deleteItem(String folderPath, String itemName) throws IOException { public int deleteItem(String folderPath, String itemName) throws IOException {
throw new UnsupportedOperationException(); String urlcompname = URIUtil.encodePath(convertItemNameToEML(itemName));
List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW);
if (!responses.isEmpty()) {
DeleteItemMethod deleteItemMethod = new DeleteItemMethod(new ItemId(responses.get(0)), DeleteType.HardDelete);
executeMethod(deleteItemMethod);
}
return HttpStatus.SC_OK;
}
@Override
public int processItem(String folderPath, String itemName) throws IOException {
String urlcompname = URIUtil.encodePath(convertItemNameToEML(itemName));
List<EWSMethod.Item> responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW);
if (!responses.isEmpty()) {
HashMap<String, String> localProperties = new HashMap<String, String>();
localProperties.put("processed", "1");
localProperties.put("read", "1");
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
ConflictResolution.AlwaysOverwrite,
CalendarItemCreateOrDeleteOperation.SendToNone,
new ItemId(responses.get(0)), buildProperties(localProperties));
executeMethod(updateItemMethod);
}
return HttpStatus.SC_OK;
} }
@Override @Override
@ -943,7 +966,7 @@ public class EwsExchangeSession extends ExchangeSession {
executeMethod(findFolderMethod); executeMethod(findFolderMethod);
EWSMethod.Item item = findFolderMethod.getResponseItem(); EWSMethod.Item item = findFolderMethod.getResponseItem();
if (item != null) { if (item != null) {
folderId = new FolderId(item.get("FolderId"), item.get("ChangeKey")); folderId = new FolderId(item);
} }
return folderId; return folderId;
} }

View File

@ -42,6 +42,16 @@ public class FolderId extends Option {
this.changeKey = changeKey; this.changeKey = changeKey;
} }
/**
* Build Folder id from response item.
*
* @param item response item
*/
public FolderId(EWSMethod.Item item) {
this(item.get("ItemId"),item.get("ChangeKey"));
}
/** /**
* @inheritDoc * @inheritDoc
*/ */

View File

@ -39,10 +39,20 @@ public class ItemId {
this.changeKey = changeKey; this.changeKey = changeKey;
} }
/**
* Build Item id from response item.
*
* @param item response item
*/
public ItemId(EWSMethod.Item item) {
this.id = item.get("ItemId");
this.changeKey = item.get("ChangeKey");
}
/** /**
* Create Item id. * Create Item id.
* *
* @param id item id * @param id item id
*/ */
public ItemId(String id) { public ItemId(String id) {
this.id = id; this.id = id;
@ -50,7 +60,7 @@ public class ItemId {
/** /**
* Write item id as XML. * Write item id as XML.
* *
* @param writer * @param writer
* @throws IOException * @throws IOException
*/ */