diff --git a/src/java/davmail/caldav/CaldavConnection.java b/src/java/davmail/caldav/CaldavConnection.java
index 1c6c6e3e..d83b6f46 100644
--- a/src/java/davmail/caldav/CaldavConnection.java
+++ b/src/java/davmail/caldav/CaldavConnection.java
@@ -214,9 +214,9 @@ public class CaldavConnection extends AbstractConnection {
} else if ("PROPFIND".equals(command) && "users".equals(paths[1]) && paths.length == 3) {
sendUserRoot(request, depth, paths[2]);
} else if ("PROPFIND".equals(command) && "users".equals(paths[1]) && paths.length == 4 && "inbox".equals(paths[3])) {
- sendInbox(request, paths[2]);
+ sendInbox(request, depth, paths[2]);
} else if ("REPORT".equals(command) && "users".equals(paths[1]) && paths.length == 4 && "inbox".equals(paths[3])) {
- reportInbox();
+ reportEvents(request);
} else if ("PROPFIND".equals(command) && "users".equals(paths[1]) && paths.length == 4 && "outbox".equals(paths[3])) {
sendOutbox(request, paths[2]);
} else if ("POST".equals(command) && "users".equals(paths[1]) && paths.length == 4 && "outbox".equals(paths[3])) {
@@ -231,7 +231,7 @@ public class CaldavConnection extends AbstractConnection {
} else if ("REPORT".equals(command) && "users".equals(paths[1]) && paths.length == 4 && "calendar".equals(paths[3])
// only current user for now
&& session.getEmail().equalsIgnoreCase(paths[2])) {
- reportCalendar(request);
+ reportEvents(request);
} else if ("PUT".equals(command) && "users".equals(paths[1]) && paths.length == 5 && "calendar".equals(paths[3])
// only current user for now
@@ -399,20 +399,17 @@ public class CaldavConnection extends AbstractConnection {
sendHttpResponse(HttpStatus.SC_OK, null, "text/html;charset=UTF-8", buffer.toString(), true);
}
- public void sendInbox(CaldavRequest request, String principal) throws IOException {
+ public void sendInbox(CaldavRequest request, int depth, String principal) throws IOException {
StringBuilder buffer = new StringBuilder();
buffer.append("");
buffer.append("");
appendInbox(buffer, principal, request);
- buffer.append("");
- sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true);
- }
-
- public void reportInbox() throws IOException {
- // inbox is always empty
- StringBuilder buffer = new StringBuilder();
- buffer.append("" +
- "");
+ if (depth == 1) {
+ DavGatewayTray.debug("Searching calendar messages...");
+ List events = session.getEventMessages();
+ DavGatewayTray.debug("Found " + events.size() + " calendar messages");
+ appendEventsResponses(buffer, request, events);
+ }
buffer.append("");
sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true);
}
@@ -450,7 +447,7 @@ public class CaldavConnection extends AbstractConnection {
}
}
- public void reportCalendar(CaldavRequest request) throws IOException {
+ public void reportEvents(CaldavRequest request) throws IOException {
List events;
List notFound = new ArrayList();
if (request.isMultiGet()) {
@@ -471,7 +468,7 @@ public class CaldavConnection extends AbstractConnection {
}
}
} else {
- events = session.getAllEvents();
+ events = new ArrayList();
}
StringBuilder buffer = new StringBuilder();
diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java
index 8932160a..cf0a8c72 100644
--- a/src/java/davmail/exchange/ExchangeSession.java
+++ b/src/java/davmail/exchange/ExchangeSession.java
@@ -631,7 +631,7 @@ public class ExchangeSession {
" ,\"urn:schemas:mailheader:message-id\", \"urn:schemas:httpmail:read\", \"DAV:isdeleted\"" +
" FROM Scope('SHALLOW TRAVERSAL OF \"" + folderUrl + "\"')\n" +
" WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False\n" +
- conditions +
+ conditions.replaceAll("<", "<").replaceAll(">", ">") +
" ORDER BY \"urn:schemas:httpmail:date\" ASC";
Enumeration folderEnum = DavGatewayHttpClientFacade.executeSearchMethod(wdr.retrieveSessionInstance(), folderUrl, searchRequest);
@@ -1191,6 +1191,14 @@ public class ExchangeSession {
}
}
+ public List getEventMessages() throws IOException {
+ String searchQuery = "Select \"DAV:getetag\"" +
+ " FROM Scope('SHALLOW TRAVERSAL OF \"" + inboxUrl + "\"')\n" +
+ " WHERE \"DAV:contentclass\" = 'urn:content-classes:calendarmessage'\n" +
+ " ORDER BY \"urn:schemas:calendar:dtstart\" DESC\n";
+ return getEvents(inboxUrl, searchQuery);
+ }
+
public List getAllEvents() throws IOException {
int caldavPastDelay = Settings.getIntProperty("davmail.caldavPastDelay", Integer.MAX_VALUE);
String dateCondition = "";
@@ -1200,19 +1208,25 @@ public class ExchangeSession {
dateCondition = " AND \"urn:schemas:calendar:dtstart\" > '" + dateFormatter.format(cal.getTime()) + "'\n";
}
- List events = new ArrayList();
- String searchRequest = "\n" +
- "\n" +
- " Select \"DAV:getetag\", \"urn:schemas:calendar:instancetype\"" +
+ String searchQuery = "Select \"DAV:getetag\"" +
" FROM Scope('SHALLOW TRAVERSAL OF \"" + calendarUrl + "\"')\n" +
" WHERE (\"urn:schemas:calendar:instancetype\" = 1\n" +
" OR (\"urn:schemas:calendar:instancetype\" = 0\n" +
dateCondition +
" )) AND \"DAV:contentclass\" = 'urn:content-classes:appointment'\n" +
- " ORDER BY \"urn:schemas:calendar:dtstart\" DESC\n" +
+ " ORDER BY \"urn:schemas:calendar:dtstart\" DESC\n";
+ return getEvents(calendarUrl, searchQuery);
+ }
+
+ public List getEvents(String path, String searchQuery) throws IOException {
+ List events = new ArrayList();
+ String searchRequest = "\n" +
+ "\n" +
+ " " + searchQuery +
" \n" +
"";
- SearchMethod searchMethod = new SearchMethod(URIUtil.encodePath(calendarUrl), searchRequest);
+
+ SearchMethod searchMethod = new SearchMethod(URIUtil.encodePath(path), searchRequest);
try {
int status = wdr.retrieveSessionInstance().executeMethod(searchMethod);
// Also accept OK sent by buggy servers.