mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-06 03:08: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:
parent
90df0e2fdf
commit
944da102e3
@ -272,7 +272,12 @@ public class CaldavConnection extends AbstractConnection {
|
||||
sendHttpResponse(itemResult.status, buildEtagHeader(itemResult.etag), null, "", true);
|
||||
|
||||
} 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);
|
||||
} else if (request.isGet()) {
|
||||
if (request.path.endsWith("/")) {
|
||||
|
@ -2598,6 +2598,7 @@ public abstract class ExchangeSession {
|
||||
|
||||
/**
|
||||
* Retrieve contact photo attached to contact
|
||||
*
|
||||
* @param contact address book contact
|
||||
* @return contact photo
|
||||
* @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 itemName event name
|
||||
* @param itemName item name
|
||||
* @return HTTP status
|
||||
* @throws IOException on error
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -1206,19 +1206,19 @@ public class DavExchangeSession extends ExchangeSession {
|
||||
@Override
|
||||
public int deleteItem(String folderPath, String itemName) throws IOException {
|
||||
String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName));
|
||||
int status;
|
||||
if (inboxUrl.endsWith(folderPath)) {
|
||||
// do not delete calendar messages, mark read and processed
|
||||
ArrayList<DavConstants> list = new ArrayList<DavConstants>();
|
||||
list.add(Field.createDavProperty("processed", "1"));
|
||||
list.add(Field.createDavProperty("read", "1"));
|
||||
PropPatchMethod patchMethod = new PropPatchMethod(eventPath, list);
|
||||
DavGatewayHttpClientFacade.executeMethod(httpClient, patchMethod);
|
||||
status = HttpStatus.SC_OK;
|
||||
} else {
|
||||
status = DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath);
|
||||
}
|
||||
return status;
|
||||
return DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int processItem(String folderPath, String itemName) throws IOException {
|
||||
String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName));
|
||||
// do not delete calendar messages, mark read and processed
|
||||
ArrayList<DavConstants> list = new ArrayList<DavConstants>();
|
||||
list.add(Field.createDavProperty("processed", "1"));
|
||||
list.add(Field.createDavProperty("read", "1"));
|
||||
PropPatchMethod patchMethod = new PropPatchMethod(eventPath, list);
|
||||
DavGatewayHttpClientFacade.executeMethod(httpClient, patchMethod);
|
||||
return HttpStatus.SC_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,7 +186,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
executeMethod(createItemMethod);
|
||||
|
||||
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>();
|
||||
localProperties.put("bcc", bcc);
|
||||
UpdateItemMethod updateItemMethod = new UpdateItemMethod(MessageDisposition.SaveOnly,
|
||||
@ -249,7 +249,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
Message message = new Message();
|
||||
|
||||
// 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());
|
||||
|
||||
@ -506,7 +506,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
|
||||
protected Folder buildFolder(EWSMethod.Item item) {
|
||||
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.folderClass = item.get(ExtendedFieldURI.PR_CONTAINER_CLASS.getResponseName());
|
||||
folder.etag = item.get(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME.getResponseName());
|
||||
@ -651,7 +651,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
ItemId itemId;
|
||||
|
||||
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());
|
||||
etag = response.get(Field.get("etag").getResponseName());
|
||||
@ -729,7 +729,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
ItemId itemId;
|
||||
|
||||
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());
|
||||
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) {
|
||||
super(folderPath, itemName, contentClass, itemBody, etag, noneMatch);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected ItemResult createOrUpdate(byte[] content) throws IOException {
|
||||
@ -848,7 +848,30 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
|
||||
@Override
|
||||
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
|
||||
@ -943,7 +966,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
executeMethod(findFolderMethod);
|
||||
EWSMethod.Item item = findFolderMethod.getResponseItem();
|
||||
if (item != null) {
|
||||
folderId = new FolderId(item.get("FolderId"), item.get("ChangeKey"));
|
||||
folderId = new FolderId(item);
|
||||
}
|
||||
return folderId;
|
||||
}
|
||||
|
@ -42,6 +42,16 @@ public class FolderId extends Option {
|
||||
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
|
||||
*/
|
||||
|
@ -39,10 +39,20 @@ public class ItemId {
|
||||
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.
|
||||
*
|
||||
* @param id item id
|
||||
* @param id item id
|
||||
*/
|
||||
public ItemId(String id) {
|
||||
this.id = id;
|
||||
@ -50,7 +60,7 @@ public class ItemId {
|
||||
|
||||
/**
|
||||
* Write item id as XML.
|
||||
*
|
||||
*
|
||||
* @param writer
|
||||
* @throws IOException
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user