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:
parent
0ac3b1a938
commit
8cb7724abe
@ -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;
|
||||||
}
|
}
|
||||||
|
if ("ATTENDEE".equals(key)) {
|
||||||
|
attendees.add(value);
|
||||||
|
attendeeKeyMap.put(value, fullkey);
|
||||||
|
} else {
|
||||||
valueMap.put(key, value);
|
valueMap.put(key, value);
|
||||||
keyMap.put(key, fullkey);
|
|
||||||
}
|
}
|
||||||
String freeBusy = session.getFreebusy(valueMap);
|
}
|
||||||
|
// get freebusy for each attendee
|
||||||
|
HashMap<String, String> freeBusyMap = new HashMap<String, String>();
|
||||||
|
for (String attendee : attendees) {
|
||||||
|
String freeBusy = session.getFreebusy(attendee, valueMap);
|
||||||
if (freeBusy != null) {
|
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()) {
|
||||||
|
String attendee = entry.getKey();
|
||||||
|
response.append("<C:response>")
|
||||||
.append("<C:recipient>")
|
.append("<C:recipient>")
|
||||||
.append("<D:href>").append(valueMap.get("ATTENDEE")).append("</D:href>")
|
.append("<D:href>").append(attendee).append("</D:href>")
|
||||||
.append("</C:recipient>")
|
.append("</C:recipient>")
|
||||||
.append("<C:request-status>2.0;Success</C:request-status>")
|
.append("<C:request-status>2.0;Success</C:request-status>")
|
||||||
.append("<C:calendar-data>BEGIN:VCALENDAR\n")
|
.append("<C:calendar-data>BEGIN:VCALENDAR").append((char) 13).append((char) 10)
|
||||||
.append("VERSION:2.0\n")
|
.append("VERSION:2.0").append((char) 13).append((char) 10)
|
||||||
.append("PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN\n")
|
.append("PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN").append((char) 13).append((char) 10)
|
||||||
.append("METHOD:REPLY\n")
|
.append("METHOD:REPLY").append((char) 13).append((char) 10)
|
||||||
.append("BEGIN:VFREEBUSY\n")
|
.append("BEGIN:VFREEBUSY").append((char) 13).append((char) 10)
|
||||||
.append("DTSTAMP:").append(valueMap.get("DTSTAMP")).append("\n")
|
.append("DTSTAMP:").append(valueMap.get("DTSTAMP")).append("").append((char) 13).append((char) 10)
|
||||||
.append("ORGANIZER:").append(valueMap.get("ORGANIZER")).append("\n")
|
.append("ORGANIZER:").append(valueMap.get("ORGANIZER")).append("").append((char) 13).append((char) 10)
|
||||||
.append("DTSTART:").append(valueMap.get("DTSTART")).append("\n")
|
.append("DTSTART:").append(valueMap.get("DTSTART")).append("").append((char) 13).append((char) 10)
|
||||||
.append("DTEND:").append(valueMap.get("DTEND")).append("\n")
|
.append("DTEND:").append(valueMap.get("DTEND")).append("").append((char) 13).append((char) 10)
|
||||||
.append("UID:").append(valueMap.get("UID")).append("\n")
|
.append("UID:").append(valueMap.get("UID")).append("").append((char) 13).append((char) 10)
|
||||||
.append(keyMap.get("ATTENDEE")).append(";").append(valueMap.get("ATTENDEE")).append("\n")
|
.append(attendeeKeyMap.get(attendee)).append(":").append(attendee).append("").append((char) 13).append((char) 10);
|
||||||
.append("FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:").append(freeBusy).append("\n")
|
if (entry.getValue().length() > 0) {
|
||||||
.append("END:VFREEBUSY\n")
|
response.append("FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:").append(entry.getValue()).append("").append((char) 13).append((char) 10);
|
||||||
|
}
|
||||||
|
response.append("END:VFREEBUSY").append((char) 13).append((char) 10)
|
||||||
.append("END:VCALENDAR")
|
.append("END:VCALENDAR")
|
||||||
.append("</C:calendar-data>")
|
.append("</C:calendar-data>")
|
||||||
.append("</C:response>")
|
.append("</C:response>");
|
||||||
.append("</C:schedule-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);
|
||||||
|
Loading…
Reference in New Issue
Block a user