mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Added support for proper deletions in WebDAV. Deleting a message the first time moves it to the (currently hardcoded) Deleted Items. Deleting an item in 'Deleted Items' will remove it completely.
This commit is contained in:
parent
46d4619ffb
commit
409acd0134
@ -340,7 +340,7 @@ public class WebDavStore extends Store {
|
|||||||
StringBuffer buffer = new StringBuffer(600);
|
StringBuffer buffer = new StringBuffer(600);
|
||||||
buffer.append("<?xml version='1.0' ?>");
|
buffer.append("<?xml version='1.0' ?>");
|
||||||
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n");
|
buffer.append("<a:searchrequest xmlns:a='DAV:'><a:sql>\r\n");
|
||||||
buffer.append("SELECT \"urn:schemas:httpmail:read\", \"DAV:uid\"\r\n");
|
buffer.append("SELECT \"urn:schemas:httpmail:read\", \"DAV:uid\", \"DAV:href\"\r\n");
|
||||||
buffer.append(" FROM \"\"\r\n");
|
buffer.append(" FROM \"\"\r\n");
|
||||||
buffer.append(" WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=False AND ");
|
buffer.append(" WHERE \"DAV:ishidden\"=False AND \"DAV:isfolder\"=False AND ");
|
||||||
for (int i = 0, count = uids.length; i < count; i++) {
|
for (int i = 0, count = uids.length; i < count; i++) {
|
||||||
@ -1384,19 +1384,31 @@ public class WebDavStore extends Store {
|
|||||||
for (int i = 0, count = uids.length; i < count; i++) {
|
for (int i = 0, count = uids.length; i < count; i++) {
|
||||||
try {
|
try {
|
||||||
int status_code = -1;
|
int status_code = -1;
|
||||||
HttpGeneric httpmethod = new HttpGeneric(uidToUrl.get(uids[i]));
|
String uid = uids[i];
|
||||||
|
String url = uidToUrl.get(uids[i]);
|
||||||
|
HttpGeneric httpmethod = new HttpGeneric(url);
|
||||||
HttpResponse response;
|
HttpResponse response;
|
||||||
HttpEntity entity;
|
HttpEntity entity;
|
||||||
|
String destinationUrl = generateDeleteUrl(url);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the destination is the same as the origin, assume delete forever
|
||||||
|
*/
|
||||||
|
if (destinationUrl.equals(url)) {
|
||||||
httpmethod.setMethod("DELETE");
|
httpmethod.setMethod("DELETE");
|
||||||
httpmethod.setHeader("Brief", "t");
|
httpmethod.setHeader("Brief", "t");
|
||||||
|
} else {
|
||||||
|
httpmethod.setMethod("MOVE");
|
||||||
|
httpmethod.setHeader("Destination", generateDeleteUrl(url));
|
||||||
|
httpmethod.setHeader("Brief", "t");
|
||||||
|
}
|
||||||
|
|
||||||
response = httpclient.execute(httpmethod);
|
response = httpclient.execute(httpmethod);
|
||||||
status_code = response.getStatusLine().getStatusCode();
|
status_code = response.getStatusLine().getStatusCode();
|
||||||
|
|
||||||
if (status_code < 200 ||
|
if (status_code < 200 ||
|
||||||
status_code > 300) {
|
status_code > 300) {
|
||||||
throw new IOException("Error deleting message url: "+urls[i]+" \nResponse Code: "+status_code);
|
throw new IOException("Error deleting message url, Response Code: "+status_code);
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException uee) {
|
} catch (UnsupportedEncodingException uee) {
|
||||||
Log.e(Email.LOG_TAG, "UnsupportedEncodingException: " + uee);
|
Log.e(Email.LOG_TAG, "UnsupportedEncodingException: " + uee);
|
||||||
@ -1406,6 +1418,14 @@ public class WebDavStore extends Store {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String generateDeleteUrl(String startUrl) {
|
||||||
|
String[] urlParts = startUrl.split("/");
|
||||||
|
String filename = urlParts[urlParts.length - 1];
|
||||||
|
String finalUrl = WebDavStore.this.mUrl + "Deleted%20Items/" + filename;
|
||||||
|
|
||||||
|
return finalUrl;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendMessages(Message[] messages) throws MessagingException {
|
public void appendMessages(Message[] messages) throws MessagingException {
|
||||||
appendMessages(messages, false);
|
appendMessages(messages, false);
|
||||||
|
Loading…
Reference in New Issue
Block a user