mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-14 03:32:22 -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:
parent
65413add29
commit
e254cc0cf9
@ -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,63 +233,58 @@ 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(lastPath)) {
|
||||||
} else if (request.isPropFind() && "outbox".equals(folderName)) {
|
sendOutbox(request);
|
||||||
sendOutbox(request);
|
} else if (request.isPost() && "outbox".equals(lastPath)) {
|
||||||
} else if (request.isPost() && "outbox".equals(folderName)) {
|
if (request.isFreeBusy()) {
|
||||||
if (request.isFreeBusy()) {
|
sendFreeBusy(request.getBody());
|
||||||
sendFreeBusy(request.getBody());
|
|
||||||
} else {
|
|
||||||
int status = session.sendEvent(request.getBody());
|
|
||||||
sendHttpResponse(status);
|
|
||||||
}
|
|
||||||
} else if (request.isPropFind()) {
|
|
||||||
sendCalendar(request);
|
|
||||||
} else if (request.isPropPatch()) {
|
|
||||||
patchCalendar(request);
|
|
||||||
} else if (request.isReport()) {
|
|
||||||
reportEvents(request);
|
|
||||||
} else {
|
} else {
|
||||||
sendUnsupported(request);
|
int status = session.sendEvent(request.getBody());
|
||||||
}
|
|
||||||
// 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 noneMatch = request.getHeader("if-none-match");
|
|
||||||
ExchangeSession.EventResult eventResult = session.createOrUpdateEvent(request.getExchangeFolderPath(), eventName, request.getBody(), etag, noneMatch);
|
|
||||||
sendHttpResponse(eventResult.status, buildEtagHeader(eventResult.etag), null, "", true);
|
|
||||||
|
|
||||||
} else if (request.isDelete()) {
|
|
||||||
int status = session.deleteEvent(request.getExchangeFolderPath(), eventName);
|
|
||||||
sendHttpResponse(status);
|
sendHttpResponse(status);
|
||||||
} else if (request.isGet()) {
|
|
||||||
ExchangeSession.Event event = session.getEvent(request.getExchangeFolderPath(), eventName);
|
|
||||||
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(event.getEtag()), "text/calendar;charset=UTF-8", event.getICS(), true);
|
|
||||||
} else if (request.isHead()) {
|
|
||||||
// test event
|
|
||||||
ExchangeSession.Event event = session.getEvent(request.getExchangeFolderPath(), eventName);
|
|
||||||
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(event.getEtag()), "text/calendar;charset=UTF-8", (byte[]) null, true);
|
|
||||||
} else {
|
|
||||||
sendUnsupported(request);
|
|
||||||
}
|
}
|
||||||
|
} else if (request.isPropFind()) {
|
||||||
|
sendCalendar(request);
|
||||||
|
} else if (request.isPropPatch()) {
|
||||||
|
patchCalendar(request);
|
||||||
|
} else if (request.isReport()) {
|
||||||
|
reportEvents(request);
|
||||||
|
// event requests
|
||||||
|
} else if (request.isPut()) {
|
||||||
|
String etag = request.getHeader("if-match");
|
||||||
|
String noneMatch = request.getHeader("if-none-match");
|
||||||
|
ExchangeSession.EventResult eventResult = session.createOrUpdateEvent(request.getExchangeFolderPath(), lastPath, request.getBody(), etag, noneMatch);
|
||||||
|
sendHttpResponse(eventResult.status, buildEtagHeader(eventResult.etag), null, "", true);
|
||||||
|
|
||||||
|
} else if (request.isDelete()) {
|
||||||
|
int status = session.deleteEvent(request.getExchangeFolderPath(), lastPath);
|
||||||
|
sendHttpResponse(status);
|
||||||
|
} else if (request.isGet()) {
|
||||||
|
ExchangeSession.Event event = session.getEvent(request.getExchangeFolderPath(), lastPath);
|
||||||
|
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(event.getEtag()), "text/calendar;charset=UTF-8", event.getICS(), true);
|
||||||
|
} else if (request.isHead()) {
|
||||||
|
// test event
|
||||||
|
ExchangeSession.Event event = session.getEvent(request.getExchangeFolderPath(), lastPath);
|
||||||
|
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(event.getEtag()), "text/calendar;charset=UTF-8", (byte[]) null, true);
|
||||||
} else {
|
} else {
|
||||||
sendUnsupported(request);
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user