mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
Caldav: implement tasks delete over WebDav
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1741 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
a1a06aff00
commit
92dabe10f2
@ -1253,6 +1253,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
displayName = getPropertyIfExists(properties, "displayname");
|
displayName = getPropertyIfExists(properties, "displayname");
|
||||||
subject = getPropertyIfExists(properties, "subject");
|
subject = getPropertyIfExists(properties, "subject");
|
||||||
instancetype = getPropertyIfExists(properties, "instancetype");
|
instancetype = getPropertyIfExists(properties, "instancetype");
|
||||||
|
contentClass = getPropertyIfExists(properties, "contentclass");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getPermanentUrl() {
|
protected String getPermanentUrl() {
|
||||||
@ -1300,7 +1301,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
@Override
|
@Override
|
||||||
public byte[] getEventContent() throws IOException {
|
public byte[] getEventContent() throws IOException {
|
||||||
byte[] result = null;
|
byte[] result = null;
|
||||||
LOGGER.debug("Get event subject: " + subject + " permanentUrl: " + permanentUrl);
|
LOGGER.debug("Get event subject: " + subject + "href: "+getHref()+" permanentUrl: " + permanentUrl);
|
||||||
// try to get PR_INTERNET_CONTENT
|
// try to get PR_INTERNET_CONTENT
|
||||||
try {
|
try {
|
||||||
result = getICSFromInternetContentProperty();
|
result = getICSFromInternetContentProperty();
|
||||||
@ -1518,8 +1519,48 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ItemResult createOrUpdate() throws IOException {
|
public ItemResult createOrUpdate() throws IOException {
|
||||||
byte[] mimeContent = createMimeContent();
|
ItemResult itemResult = new ItemResult();
|
||||||
|
if (vCalendar.isTodo()) {
|
||||||
|
if ((mailPath + calendarName).equals(folderPath)) {
|
||||||
|
folderPath = mailPath + tasksName;
|
||||||
|
}
|
||||||
String encodedHref = URIUtil.encodePath(getHref());
|
String encodedHref = URIUtil.encodePath(getHref());
|
||||||
|
Set<PropertyValue> propertyValues = new HashSet<PropertyValue>();
|
||||||
|
// set contentclass on create
|
||||||
|
if (noneMatch != null) {
|
||||||
|
propertyValues.add(Field.createPropertyValue("contentclass", "urn:content-classes:task"));
|
||||||
|
propertyValues.add(Field.createPropertyValue("outlookmessageclass", "IPM.Task"));
|
||||||
|
propertyValues.add(Field.createPropertyValue("calendaruid", vCalendar.getFirstVeventPropertyValue("UID")));
|
||||||
|
}
|
||||||
|
propertyValues.add(Field.createPropertyValue("subject", vCalendar.getFirstVeventPropertyValue("SUMMARY")));
|
||||||
|
propertyValues.add(Field.createPropertyValue("description", vCalendar.getFirstVeventPropertyValue("DESCRIPTION")));
|
||||||
|
|
||||||
|
ExchangePropPatchMethod propPatchMethod = new ExchangePropPatchMethod(encodedHref, propertyValues);
|
||||||
|
propPatchMethod.setRequestHeader("Translate", "f");
|
||||||
|
if (etag != null) {
|
||||||
|
propPatchMethod.setRequestHeader("If-Match", etag);
|
||||||
|
}
|
||||||
|
if (noneMatch != null) {
|
||||||
|
propPatchMethod.setRequestHeader("If-None-Match", noneMatch);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
httpClient.executeMethod(propPatchMethod);
|
||||||
|
} finally {
|
||||||
|
propPatchMethod.releaseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
int status = DavGatewayHttpClientFacade.executeHttpMethod(httpClient, propPatchMethod);
|
||||||
|
if (status == HttpStatus.SC_MULTI_STATUS) {
|
||||||
|
Item newItem = getItem(folderPath, itemName);
|
||||||
|
itemResult.status = propPatchMethod.getResponseStatusCode();
|
||||||
|
itemResult.etag = newItem.etag;
|
||||||
|
} else {
|
||||||
|
itemResult.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
String encodedHref = URIUtil.encodePath(getHref());
|
||||||
|
byte[] mimeContent = createMimeContent();
|
||||||
PutMethod putMethod = internalCreateOrUpdate(encodedHref, mimeContent);
|
PutMethod putMethod = internalCreateOrUpdate(encodedHref, mimeContent);
|
||||||
int status = putMethod.getStatusCode();
|
int status = putMethod.getStatusCode();
|
||||||
|
|
||||||
@ -1546,7 +1587,6 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
LOGGER.warn("Unable to create or update event " + status + ' ' + putMethod.getStatusLine());
|
LOGGER.warn("Unable to create or update event " + status + ' ' + putMethod.getStatusLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemResult itemResult = new ItemResult();
|
|
||||||
// 440 means forbidden on Exchange
|
// 440 means forbidden on Exchange
|
||||||
if (status == 440) {
|
if (status == 440) {
|
||||||
status = HttpStatus.SC_FORBIDDEN;
|
status = HttpStatus.SC_FORBIDDEN;
|
||||||
@ -1574,6 +1614,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
itemResult.etag = newItem.etag;
|
itemResult.etag = newItem.etag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return itemResult;
|
return itemResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2032,7 +2073,8 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
}
|
}
|
||||||
return contacts.get(0);
|
return contacts.get(0);
|
||||||
} else if ("urn:content-classes:appointment".equals(contentClass)
|
} else if ("urn:content-classes:appointment".equals(contentClass)
|
||||||
|| "urn:content-classes:calendarmessage".equals(contentClass)) {
|
|| "urn:content-classes:calendarmessage".equals(contentClass)
|
||||||
|
|| "urn:content-classes:task".equals(contentClass)) {
|
||||||
return new Event(responses[0]);
|
return new Event(responses[0]);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("wrong contentclass on item " + itemPath + ": " + contentClass);
|
LOGGER.warn("wrong contentclass on item " + itemPath + ": " + contentClass);
|
||||||
@ -2100,7 +2142,15 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
@Override
|
@Override
|
||||||
public void deleteItem(String folderPath, String itemName) throws IOException {
|
public void deleteItem(String folderPath, String itemName) throws IOException {
|
||||||
String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName));
|
String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName));
|
||||||
DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath);
|
int status = DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath);
|
||||||
|
if (status == HttpStatus.SC_NOT_FOUND && isMainCalendar(folderPath)) {
|
||||||
|
// retry in tasks folder
|
||||||
|
eventPath = URIUtil.encodePath(getFolderPath(TASKS) + '/' + convertItemNameToEML(itemName));
|
||||||
|
status = DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath);
|
||||||
|
}
|
||||||
|
if (status == HttpStatus.SC_NOT_FOUND) {
|
||||||
|
LOGGER.debug("Unable to delete "+itemName+": item not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -418,8 +418,9 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
* @param httpClient Http client instance
|
* @param httpClient Http client instance
|
||||||
* @param path Path to be deleted
|
* @param path Path to be deleted
|
||||||
* @throws IOException on error
|
* @throws IOException on error
|
||||||
|
* @return http status
|
||||||
*/
|
*/
|
||||||
public static void executeDeleteMethod(HttpClient httpClient, String path) throws IOException {
|
public static int executeDeleteMethod(HttpClient httpClient, String path) throws IOException {
|
||||||
DeleteMethod deleteMethod = new DeleteMethod(path);
|
DeleteMethod deleteMethod = new DeleteMethod(path);
|
||||||
deleteMethod.setFollowRedirects(false);
|
deleteMethod.setFollowRedirects(false);
|
||||||
|
|
||||||
@ -428,6 +429,7 @@ public final class DavGatewayHttpClientFacade {
|
|||||||
if (status != HttpStatus.SC_OK && status != HttpStatus.SC_NOT_FOUND) {
|
if (status != HttpStatus.SC_OK && status != HttpStatus.SC_NOT_FOUND) {
|
||||||
throw DavGatewayHttpClientFacade.buildHttpException(deleteMethod);
|
throw DavGatewayHttpClientFacade.buildHttpException(deleteMethod);
|
||||||
}
|
}
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user