1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 11:12:22 -05:00

Caldav: Allow multiple attendees in VFREEBUSY request (iCal support)

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@352 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-02-12 10:10:23 +00:00
parent 0ac3b1a938
commit 8cb7724abe

View File

@ -63,18 +63,18 @@ public class CaldavConnection extends AbstractConnection {
} }
char[] buffer = new char[size]; char[] buffer = new char[size];
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
int actualSize = in.read(buffer); int actualSize = in.read(buffer);
builder.append(buffer, 0, actualSize); builder.append(buffer, 0, actualSize);
if (actualSize < 0) { if (actualSize < 0) {
throw new IOException("End of stream reached reading content"); throw new IOException("End of stream reached reading content");
} }
// dirty hack to ensure full content read // dirty hack to ensure full content read
// TODO : replace with a dedicated reader // TODO : replace with a dedicated reader
while (builder.toString().getBytes("UTF-8").length < size) { while (builder.toString().getBytes("UTF-8").length < size) {
actualSize = in.read(buffer); actualSize = in.read(buffer);
builder.append(buffer, 0, actualSize); builder.append(buffer, 0, actualSize);
} }
return builder.toString(); return builder.toString();
} }
} }
@ -597,8 +597,9 @@ public class CaldavConnection extends AbstractConnection {
} }
public void sendFreeBusy(String body) throws IOException { public void sendFreeBusy(String body) throws IOException {
Map<String, String> valueMap = new HashMap<String, String>(); HashMap<String, String> valueMap = new HashMap<String, String>();
Map<String, String> keyMap = new HashMap<String, String>(); ArrayList<String> attendees = new ArrayList<String>();
HashMap<String, String> attendeeKeyMap = new HashMap<String, String>();
ICSBufferedReader reader = new ICSBufferedReader(new StringReader(body)); ICSBufferedReader reader = new ICSBufferedReader(new StringReader(body));
String line; String line;
String key; String key;
@ -615,37 +616,53 @@ public class CaldavConnection extends AbstractConnection {
} else { } else {
key = fullkey; key = fullkey;
} }
valueMap.put(key, value); if ("ATTENDEE".equals(key)) {
keyMap.put(key, fullkey); attendees.add(value);
attendeeKeyMap.put(value, fullkey);
} else {
valueMap.put(key, value);
}
} }
String freeBusy = session.getFreebusy(valueMap); // get freebusy for each attendee
if (freeBusy != null) { HashMap<String, String> freeBusyMap = new HashMap<String, String>();
for (String attendee : attendees) {
String freeBusy = session.getFreebusy(attendee, valueMap);
if (freeBusy != null) {
freeBusyMap.put(attendee, freeBusy);
}
}
if (!freeBusyMap.isEmpty()) {
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();
response.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>") response.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>")
.append("<C:schedule-response xmlns:D=\"DAV:\" xmlns:C=\"urn:ietf:params:xml:ns:caldav\">") .append("<C:schedule-response xmlns:D=\"DAV:\" xmlns:C=\"urn:ietf:params:xml:ns:caldav\">");
.append("<C:response>") for (Map.Entry<String, String> entry : freeBusyMap.entrySet()) {
.append("<C:recipient>") String attendee = entry.getKey();
.append("<D:href>").append(valueMap.get("ATTENDEE")).append("</D:href>") response.append("<C:response>")
.append("</C:recipient>") .append("<C:recipient>")
.append("<C:request-status>2.0;Success</C:request-status>") .append("<D:href>").append(attendee).append("</D:href>")
.append("<C:calendar-data>BEGIN:VCALENDAR\n") .append("</C:recipient>")
.append("VERSION:2.0\n") .append("<C:request-status>2.0;Success</C:request-status>")
.append("PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN\n") .append("<C:calendar-data>BEGIN:VCALENDAR").append((char) 13).append((char) 10)
.append("METHOD:REPLY\n") .append("VERSION:2.0").append((char) 13).append((char) 10)
.append("BEGIN:VFREEBUSY\n") .append("PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN").append((char) 13).append((char) 10)
.append("DTSTAMP:").append(valueMap.get("DTSTAMP")).append("\n") .append("METHOD:REPLY").append((char) 13).append((char) 10)
.append("ORGANIZER:").append(valueMap.get("ORGANIZER")).append("\n") .append("BEGIN:VFREEBUSY").append((char) 13).append((char) 10)
.append("DTSTART:").append(valueMap.get("DTSTART")).append("\n") .append("DTSTAMP:").append(valueMap.get("DTSTAMP")).append("").append((char) 13).append((char) 10)
.append("DTEND:").append(valueMap.get("DTEND")).append("\n") .append("ORGANIZER:").append(valueMap.get("ORGANIZER")).append("").append((char) 13).append((char) 10)
.append("UID:").append(valueMap.get("UID")).append("\n") .append("DTSTART:").append(valueMap.get("DTSTART")).append("").append((char) 13).append((char) 10)
.append(keyMap.get("ATTENDEE")).append(";").append(valueMap.get("ATTENDEE")).append("\n") .append("DTEND:").append(valueMap.get("DTEND")).append("").append((char) 13).append((char) 10)
.append("FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:").append(freeBusy).append("\n") .append("UID:").append(valueMap.get("UID")).append("").append((char) 13).append((char) 10)
.append("END:VFREEBUSY\n") .append(attendeeKeyMap.get(attendee)).append(":").append(attendee).append("").append((char) 13).append((char) 10);
.append("END:VCALENDAR") if (entry.getValue().length() > 0) {
.append("</C:calendar-data>") response.append("FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:").append(entry.getValue()).append("").append((char) 13).append((char) 10);
.append("</C:response>") }
.append("</C:schedule-response>"); response.append("END:VFREEBUSY").append((char) 13).append((char) 10)
.append("END:VCALENDAR")
.append("</C:calendar-data>")
.append("</C:response>");
}
response.append("</C:schedule-response>");
sendHttpResponse(HttpStatus.SC_OK, null, "text/xml;charset=UTF-8", response.toString(), true); sendHttpResponse(HttpStatus.SC_OK, null, "text/xml;charset=UTF-8", response.toString(), true);
} else { } else {
sendHttpResponse(HttpStatus.SC_NOT_FOUND, null, "text/plain", "Unknown recipient: " + valueMap.get("ATTENDEE"), true); sendHttpResponse(HttpStatus.SC_NOT_FOUND, null, "text/plain", "Unknown recipient: " + valueMap.get("ATTENDEE"), true);