mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
Caldav: Get calendarmessages in Caldav inbox from Exchange Inbox
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@383 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
1b7a121318
commit
f645065bde
@ -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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
buffer.append("<D:multistatus xmlns:D=\"DAV:\" xmlns:C=\"urn:ietf:params:xml:ns:caldav\">");
|
||||
appendInbox(buffer, principal, request);
|
||||
buffer.append("</D:multistatus>");
|
||||
sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true);
|
||||
if (depth == 1) {
|
||||
DavGatewayTray.debug("Searching calendar messages...");
|
||||
List<ExchangeSession.Event> events = session.getEventMessages();
|
||||
DavGatewayTray.debug("Found " + events.size() + " calendar messages");
|
||||
appendEventsResponses(buffer, request, events);
|
||||
}
|
||||
|
||||
public void reportInbox() throws IOException {
|
||||
// inbox is always empty
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<D:multistatus xmlns:D=\"DAV:\">");
|
||||
buffer.append("</D:multistatus>");
|
||||
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<ExchangeSession.Event> events;
|
||||
List<String> notFound = new ArrayList<String>();
|
||||
if (request.isMultiGet()) {
|
||||
@ -471,7 +468,7 @@ public class CaldavConnection extends AbstractConnection {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
events = session.getAllEvents();
|
||||
events = new ArrayList<ExchangeSession.Event>();
|
||||
}
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
@ -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<Event> 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<Event> 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<Event> events = new ArrayList<Event>();
|
||||
String searchRequest = "<?xml version=\"1.0\"?>\n" +
|
||||
"<d:searchrequest xmlns:d=\"DAV:\">\n" +
|
||||
" <d:sql> 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<Event> getEvents(String path, String searchQuery) throws IOException {
|
||||
List<Event> events = new ArrayList<Event>();
|
||||
String searchRequest = "<?xml version=\"1.0\"?>\n" +
|
||||
"<d:searchrequest xmlns:d=\"DAV:\">\n" +
|
||||
" <d:sql>" + searchQuery +
|
||||
" </d:sql>\n" +
|
||||
"</d:searchrequest>";
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user