From 9f0981b294101d04f6120cee8923db6638843762 Mon Sep 17 00:00:00 2001 From: mguessan Date: Wed, 24 Dec 2008 15:29:03 +0000 Subject: [PATCH] iCal fix : Also send events on propfind if depth is 1 git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@251 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/caldav/CaldavConnection.java | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/src/java/davmail/caldav/CaldavConnection.java b/src/java/davmail/caldav/CaldavConnection.java index 8f675227..0e58c041 100644 --- a/src/java/davmail/caldav/CaldavConnection.java +++ b/src/java/davmail/caldav/CaldavConnection.java @@ -234,6 +234,10 @@ public class CaldavConnection extends AbstractConnection { buffer.append(" HTTP/1.1 200 OK\n"); buffer.append(" \n"); buffer.append(" \n"); + // if depth is 1, also send events + if (depth > 0) { + appendEventsResponses(buffer, request, session.getAllEvents()); + } buffer.append("\n"); HashMap responseHeaders = new HashMap(); @@ -293,35 +297,11 @@ public class CaldavConnection extends AbstractConnection { StringBuilder buffer = new StringBuilder(); buffer.append("\n" + "\n"); - for (ExchangeSession.Event event : events) { + appendEventsResponses(buffer, request, events); - String eventPath = event.getPath().replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); - buffer.append("\n"); - buffer.append(" /calendar").append(eventPath).append("\n"); - buffer.append(" \n"); - buffer.append(" \n"); - if (request.hasProperty("calendar-data")) { - String ics = event.getICS(); - if (ics != null && ics.length() > 0) { - ics = ics.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); - buffer.append(" "); - buffer.append(ics); - buffer.append("\n"); - } - } - if (request.hasProperty("getetag")) { - buffer.append(" ").append(event.getEtag()).append("\n"); - } - buffer.append(" \n"); - buffer.append(" HTTP/1.1 200 OK\n"); - buffer.append(" \n"); - buffer.append(" \n"); - - } // send not found events errors for (String href : notFound) { - buffer.append("\n"); + buffer.append(" \n"); buffer.append(" ").append(href).append("\n"); buffer.append(" \n"); buffer.append(" HTTP/1.1 404 Not Found\n"); @@ -410,6 +390,36 @@ public class CaldavConnection extends AbstractConnection { } + protected void appendEventsResponses(StringBuilder buffer, CaldavRequest request, List events) throws IOException { + int size = events.size(); + int count = 0; + for (ExchangeSession.Event event : events) { + DavGatewayTray.debug("Retrieving event "+(++count)+"/"+size); + String eventPath = event.getPath().replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); + buffer.append("\n"); + buffer.append(" /calendar").append(eventPath).append("\n"); + buffer.append(" \n"); + buffer.append(" \n"); + if (request.hasProperty("calendar-data")) { + String ics = event.getICS(); + if (ics != null && ics.length() > 0) { + ics = ics.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); + buffer.append(" "); + buffer.append(ics); + buffer.append("\n"); + } + } + if (request.hasProperty("getetag")) { + buffer.append(" ").append(event.getEtag()).append("\n"); + } + buffer.append(" \n"); + buffer.append(" HTTP/1.1 200 OK\n"); + buffer.append(" \n"); + buffer.append(" \n"); + + } + } public void sendErr(int status, Exception e) throws IOException { String message = e.getMessage();