1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-14 11:42:23 -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:
mguessan 2009-02-20 17:44:30 +00:00
parent 1b7a121318
commit f645065bde
2 changed files with 33 additions and 22 deletions

View File

@ -214,9 +214,9 @@ public class CaldavConnection extends AbstractConnection {
} else if ("PROPFIND".equals(command) && "users".equals(paths[1]) && paths.length == 3) { } else if ("PROPFIND".equals(command) && "users".equals(paths[1]) && paths.length == 3) {
sendUserRoot(request, depth, paths[2]); sendUserRoot(request, depth, paths[2]);
} else if ("PROPFIND".equals(command) && "users".equals(paths[1]) && paths.length == 4 && "inbox".equals(paths[3])) { } 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])) { } 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])) { } else if ("PROPFIND".equals(command) && "users".equals(paths[1]) && paths.length == 4 && "outbox".equals(paths[3])) {
sendOutbox(request, paths[2]); sendOutbox(request, paths[2]);
} else if ("POST".equals(command) && "users".equals(paths[1]) && paths.length == 4 && "outbox".equals(paths[3])) { } 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]) } else if ("REPORT".equals(command) && "users".equals(paths[1]) && paths.length == 4 && "calendar".equals(paths[3])
// only current user for now // only current user for now
&& session.getEmail().equalsIgnoreCase(paths[2])) { && 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]) } else if ("PUT".equals(command) && "users".equals(paths[1]) && paths.length == 5 && "calendar".equals(paths[3])
// only current user for now // 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); 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(); StringBuilder buffer = new StringBuilder();
buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
buffer.append("<D:multistatus xmlns:D=\"DAV:\" xmlns:C=\"urn:ietf:params:xml:ns:caldav\">"); buffer.append("<D:multistatus xmlns:D=\"DAV:\" xmlns:C=\"urn:ietf:params:xml:ns:caldav\">");
appendInbox(buffer, principal, request); appendInbox(buffer, principal, request);
buffer.append("</D:multistatus>"); if (depth == 1) {
sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); DavGatewayTray.debug("Searching calendar messages...");
} List<ExchangeSession.Event> events = session.getEventMessages();
DavGatewayTray.debug("Found " + events.size() + " calendar messages");
public void reportInbox() throws IOException { appendEventsResponses(buffer, request, events);
// 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>"); buffer.append("</D:multistatus>");
sendHttpResponse(HttpStatus.SC_MULTI_STATUS, null, "text/xml;charset=UTF-8", buffer.toString(), true); 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<ExchangeSession.Event> events;
List<String> notFound = new ArrayList<String>(); List<String> notFound = new ArrayList<String>();
if (request.isMultiGet()) { if (request.isMultiGet()) {
@ -471,7 +468,7 @@ public class CaldavConnection extends AbstractConnection {
} }
} }
} else { } else {
events = session.getAllEvents(); events = new ArrayList<ExchangeSession.Event>();
} }
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();

View File

@ -631,7 +631,7 @@ public class ExchangeSession {
" ,\"urn:schemas:mailheader:message-id\", \"urn:schemas:httpmail:read\", \"DAV:isdeleted\"" + " ,\"urn:schemas:mailheader:message-id\", \"urn:schemas:httpmail:read\", \"DAV:isdeleted\"" +
" FROM Scope('SHALLOW TRAVERSAL OF \"" + folderUrl + "\"')\n" + " FROM Scope('SHALLOW TRAVERSAL OF \"" + folderUrl + "\"')\n" +
" WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False\n" + " WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False\n" +
conditions + conditions.replaceAll("<", "&lt;").replaceAll(">", "&gt;") +
" ORDER BY \"urn:schemas:httpmail:date\" ASC"; " ORDER BY \"urn:schemas:httpmail:date\" ASC";
Enumeration folderEnum = DavGatewayHttpClientFacade.executeSearchMethod(wdr.retrieveSessionInstance(), folderUrl, searchRequest); 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 { public List<Event> getAllEvents() throws IOException {
int caldavPastDelay = Settings.getIntProperty("davmail.caldavPastDelay", Integer.MAX_VALUE); int caldavPastDelay = Settings.getIntProperty("davmail.caldavPastDelay", Integer.MAX_VALUE);
String dateCondition = ""; String dateCondition = "";
@ -1200,19 +1208,25 @@ public class ExchangeSession {
dateCondition = " AND \"urn:schemas:calendar:dtstart\" > '" + dateFormatter.format(cal.getTime()) + "'\n"; dateCondition = " AND \"urn:schemas:calendar:dtstart\" > '" + dateFormatter.format(cal.getTime()) + "'\n";
} }
List<Event> events = new ArrayList<Event>(); String searchQuery = "Select \"DAV:getetag\"" +
String searchRequest = "<?xml version=\"1.0\"?>\n" +
"<d:searchrequest xmlns:d=\"DAV:\">\n" +
" <d:sql> Select \"DAV:getetag\", \"urn:schemas:calendar:instancetype\"" +
" FROM Scope('SHALLOW TRAVERSAL OF \"" + calendarUrl + "\"')\n" + " FROM Scope('SHALLOW TRAVERSAL OF \"" + calendarUrl + "\"')\n" +
" WHERE (\"urn:schemas:calendar:instancetype\" = 1\n" + " WHERE (\"urn:schemas:calendar:instancetype\" = 1\n" +
" OR (\"urn:schemas:calendar:instancetype\" = 0\n" + " OR (\"urn:schemas:calendar:instancetype\" = 0\n" +
dateCondition + dateCondition +
" )) AND \"DAV:contentclass\" = 'urn:content-classes:appointment'\n" + " )) 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:sql>\n" +
"</d:searchrequest>"; "</d:searchrequest>";
SearchMethod searchMethod = new SearchMethod(URIUtil.encodePath(calendarUrl), searchRequest);
SearchMethod searchMethod = new SearchMethod(URIUtil.encodePath(path), searchRequest);
try { try {
int status = wdr.retrieveSessionInstance().executeMethod(searchMethod); int status = wdr.retrieveSessionInstance().executeMethod(searchMethod);
// Also accept OK sent by buggy servers. // Also accept OK sent by buggy servers.