1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-14 11:42:23 -05:00

Caldav: improve public (shared) calendar support, accept calendars at any depth

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@646 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-08-05 23:23:11 +00:00
parent 65413add29
commit e254cc0cf9

View File

@ -214,10 +214,10 @@ public class CaldavConnection extends AbstractConnection {
if (request.isPropFind() && request.isPathLength(3)) { if (request.isPropFind() && request.isPathLength(3)) {
sendUserRoot(request); sendUserRoot(request);
} else { } else {
handleCalendar(request, 3); handleCalendar(request);
} }
} else if (request.isPath(1, "public")) { } else if (request.isPath(1, "public")) {
handleCalendar(request, 2); handleCalendar(request);
} else { } else {
sendUnsupported(request); sendUnsupported(request);
} }
@ -233,22 +233,25 @@ public class CaldavConnection extends AbstractConnection {
} else { } else {
sendUnsupported(request); sendUnsupported(request);
} }
} else if (request.isPath(2, "public") && request.isPathLength(4)) { } else if (request.isPath(2, "public")) {
sendPrincipal(request, "public", request.getPathElement(3)); StringBuilder prefixBuffer = new StringBuilder("public");
for (int i=3; i<request.getPathLength()-1;i++) {
prefixBuffer.append('/').append(request.getPathElement(i));
}
sendPrincipal(request, prefixBuffer.toString(), request.getLastPath());
} else { } else {
sendUnsupported(request); sendUnsupported(request);
} }
} }
protected void handleCalendar(CaldavRequest request, int depth) throws IOException { protected void handleCalendar(CaldavRequest request) throws IOException {
String folderName = request.getPathElement(depth); String lastPath = xmlDecodeName(request.getLastPath());
// folder request // folder requests
if (request.isPathLength(depth + 1)) { if (request.isPropFind() && "inbox".equals(lastPath)) {
if (request.isPropFind() && "inbox".equals(folderName)) {
sendInbox(request); sendInbox(request);
} else if (request.isPropFind() && "outbox".equals(folderName)) { } else if (request.isPropFind() && "outbox".equals(lastPath)) {
sendOutbox(request); sendOutbox(request);
} else if (request.isPost() && "outbox".equals(folderName)) { } else if (request.isPost() && "outbox".equals(lastPath)) {
if (request.isFreeBusy()) { if (request.isFreeBusy()) {
sendFreeBusy(request.getBody()); sendFreeBusy(request.getBody());
} else { } else {
@ -261,35 +264,27 @@ public class CaldavConnection extends AbstractConnection {
patchCalendar(request); patchCalendar(request);
} else if (request.isReport()) { } else if (request.isReport()) {
reportEvents(request); reportEvents(request);
} else { // event requests
sendUnsupported(request); } else if (request.isPut()) {
}
// event request
} else if (request.isPathLength(depth + 2)) {
String eventName = xmlDecodeName(request.getPathElement(depth + 1));
if (request.isPut()) {
String etag = request.getHeader("if-match"); String etag = request.getHeader("if-match");
String noneMatch = request.getHeader("if-none-match"); String noneMatch = request.getHeader("if-none-match");
ExchangeSession.EventResult eventResult = session.createOrUpdateEvent(request.getExchangeFolderPath(), eventName, request.getBody(), etag, noneMatch); ExchangeSession.EventResult eventResult = session.createOrUpdateEvent(request.getExchangeFolderPath(), lastPath, request.getBody(), etag, noneMatch);
sendHttpResponse(eventResult.status, buildEtagHeader(eventResult.etag), null, "", true); sendHttpResponse(eventResult.status, buildEtagHeader(eventResult.etag), null, "", true);
} else if (request.isDelete()) { } else if (request.isDelete()) {
int status = session.deleteEvent(request.getExchangeFolderPath(), eventName); int status = session.deleteEvent(request.getExchangeFolderPath(), lastPath);
sendHttpResponse(status); sendHttpResponse(status);
} else if (request.isGet()) { } else if (request.isGet()) {
ExchangeSession.Event event = session.getEvent(request.getExchangeFolderPath(), eventName); ExchangeSession.Event event = session.getEvent(request.getExchangeFolderPath(), lastPath);
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(event.getEtag()), "text/calendar;charset=UTF-8", event.getICS(), true); sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(event.getEtag()), "text/calendar;charset=UTF-8", event.getICS(), true);
} else if (request.isHead()) { } else if (request.isHead()) {
// test event // test event
ExchangeSession.Event event = session.getEvent(request.getExchangeFolderPath(), eventName); ExchangeSession.Event event = session.getEvent(request.getExchangeFolderPath(), lastPath);
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(event.getEtag()), "text/calendar;charset=UTF-8", (byte[]) null, true); sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(event.getEtag()), "text/calendar;charset=UTF-8", (byte[]) null, true);
} else { } else {
sendUnsupported(request); sendUnsupported(request);
} }
} else {
sendUnsupported(request);
}
} }
protected HashMap<String, String> buildEtagHeader(String etag) { protected HashMap<String, String> buildEtagHeader(String etag) {
@ -713,7 +708,7 @@ public class CaldavConnection extends AbstractConnection {
if ("users".equals(prefix)) { if ("users".equals(prefix)) {
response.appendHrefProperty("C:calendar-home-set", "/users/" + actualPrincipal + "/calendar"); response.appendHrefProperty("C:calendar-home-set", "/users/" + actualPrincipal + "/calendar");
} else { } else {
response.appendHrefProperty("C:calendar-home-set", prefix + '/' + actualPrincipal); response.appendHrefProperty("C:calendar-home-set", '/' + prefix + '/' + actualPrincipal);
} }
} }
@ -1323,7 +1318,7 @@ public class CaldavConnection extends AbstractConnection {
public void startResponse(String href) throws IOException { public void startResponse(String href) throws IOException {
writer.write("<D:response>"); writer.write("<D:response>");
writer.write("<D:href>"); writer.write("<D:href>");
writer.write(href); writer.write(xmlEncodeName(href));
writer.write("</D:href>"); writer.write("</D:href>");
} }
@ -1342,7 +1337,7 @@ public class CaldavConnection extends AbstractConnection {
} }
public void appendHrefProperty(String propertyName, String propertyValue) throws IOException { public void appendHrefProperty(String propertyName, String propertyValue) throws IOException {
appendProperty(propertyName, null, "<D:href>" + URIUtil.encodePath(propertyValue) + "</D:href>"); appendProperty(propertyName, null, "<D:href>" + URIUtil.encodePath(xmlEncodeName(propertyValue)) + "</D:href>");
} }
public void appendProperty(String propertyName) throws IOException { public void appendProperty(String propertyName) throws IOException {