mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-14 19:52:21 -05:00
CardDav: implement OSX AddressBook requests: current-user-privilege-set property, current-user-principal on root request, addressbook-home-set on principal request, addressbook-multiget REPORT request with address-data response, urn:ietf:params:xml:ns:carddav namespace
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1072 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
3f87184c7c
commit
2fca78c9a0
@ -212,6 +212,8 @@ public class CaldavConnection extends AbstractConnection {
|
|||||||
}
|
}
|
||||||
} else if (request.isPath(1, "public")) {
|
} else if (request.isPath(1, "public")) {
|
||||||
handleFolder(request);
|
handleFolder(request);
|
||||||
|
} else if (request.isPath(1, "directory")) {
|
||||||
|
sendDirectory(request);
|
||||||
} else {
|
} else {
|
||||||
sendUnsupported(request);
|
sendUnsupported(request);
|
||||||
}
|
}
|
||||||
@ -357,6 +359,9 @@ public class CaldavConnection extends AbstractConnection {
|
|||||||
if (request.hasProperty("calendar-data") && item instanceof ExchangeSession.Event) {
|
if (request.hasProperty("calendar-data") && item instanceof ExchangeSession.Event) {
|
||||||
response.appendCalendarData(item.getBody());
|
response.appendCalendarData(item.getBody());
|
||||||
}
|
}
|
||||||
|
if (request.hasProperty("address-data") && item instanceof ExchangeSession.Contact) {
|
||||||
|
response.appendContactData(item.getBody());
|
||||||
|
}
|
||||||
if (request.hasProperty("getcontenttype")) {
|
if (request.hasProperty("getcontenttype")) {
|
||||||
if (item instanceof ExchangeSession.Event) {
|
if (item instanceof ExchangeSession.Event) {
|
||||||
response.appendProperty("D:getcontenttype", "text/calendar; component=vevent");
|
response.appendProperty("D:getcontenttype", "text/calendar; component=vevent");
|
||||||
@ -438,6 +443,10 @@ public class CaldavConnection extends AbstractConnection {
|
|||||||
response.appendProperty("C:supported-calendar-component-set", "<C:comp name=\"VEVENT\"/><C:comp name=\"VTODO\"/>");
|
response.appendProperty("C:supported-calendar-component-set", "<C:comp name=\"VEVENT\"/><C:comp name=\"VTODO\"/>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.hasProperty("current-user-privilege-set")) {
|
||||||
|
response.appendProperty("D:current-user-privilege-set", "<D:privilege><D:read/><D:write/></D:privilege>");
|
||||||
|
}
|
||||||
|
|
||||||
response.endPropStatOK();
|
response.endPropStatOK();
|
||||||
response.endResponse();
|
response.endResponse();
|
||||||
return folder;
|
return folder;
|
||||||
@ -668,6 +677,7 @@ public class CaldavConnection extends AbstractConnection {
|
|||||||
events = session.getEventMessages(request.getExchangeFolderPath());
|
events = session.getEventMessages(request.getExchangeFolderPath());
|
||||||
appendEventsResponses(response, request, events);
|
appendEventsResponses(response, request, events);
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: handle contacts ?
|
||||||
events = session.getAllEvents(request.getExchangeFolderPath());
|
events = session.getAllEvents(request.getExchangeFolderPath());
|
||||||
appendEventsResponses(response, request, events);
|
appendEventsResponses(response, request, events);
|
||||||
}
|
}
|
||||||
@ -736,6 +746,9 @@ public class CaldavConnection extends AbstractConnection {
|
|||||||
if (request.hasProperty("resourcetype")) {
|
if (request.hasProperty("resourcetype")) {
|
||||||
response.appendProperty("D:resourcetype", "<D:collection/>");
|
response.appendProperty("D:resourcetype", "<D:collection/>");
|
||||||
}
|
}
|
||||||
|
if (request.hasProperty("current-user-principal")) {
|
||||||
|
response.appendHrefProperty("D:current-user-principal", "/principals/users/" + session.getEmail());
|
||||||
|
}
|
||||||
response.endPropStatOK();
|
response.endPropStatOK();
|
||||||
response.endResponse();
|
response.endResponse();
|
||||||
if (request.depth == 1) {
|
if (request.depth == 1) {
|
||||||
@ -781,6 +794,26 @@ public class CaldavConnection extends AbstractConnection {
|
|||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send caldav response for /directory/ request.
|
||||||
|
*
|
||||||
|
* @param request Caldav request
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
|
public void sendDirectory(CaldavRequest request) throws IOException {
|
||||||
|
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
|
||||||
|
response.startMultistatus();
|
||||||
|
response.startResponse("/directory/");
|
||||||
|
response.startPropstat();
|
||||||
|
if (request.hasProperty("current-user-privilege-set")) {
|
||||||
|
response.appendProperty("D:current-user-privilege-set", "<D:privilege><D:read/></D:privilege>");
|
||||||
|
}
|
||||||
|
response.endPropStatOK();
|
||||||
|
response.endResponse();
|
||||||
|
response.endMultistatus();
|
||||||
|
response.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send Caldav principal response.
|
* Send Caldav principal response.
|
||||||
*
|
*
|
||||||
@ -813,6 +846,10 @@ public class CaldavConnection extends AbstractConnection {
|
|||||||
response.appendHrefProperty("C:calendar-user-address-set", "mailto:" + actualPrincipal);
|
response.appendHrefProperty("C:calendar-user-address-set", "mailto:" + actualPrincipal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.hasProperty("addressbook-home-set") && "users".equals(prefix)) {
|
||||||
|
response.appendHrefProperty("E:addressbook-home-set", "/users/" + actualPrincipal + "/");
|
||||||
|
}
|
||||||
|
|
||||||
if ("users".equals(prefix)) {
|
if ("users".equals(prefix)) {
|
||||||
if (request.hasProperty("schedule-inbox-URL")) {
|
if (request.hasProperty("schedule-inbox-URL")) {
|
||||||
response.appendHrefProperty("C:schedule-inbox-URL", "/users/" + actualPrincipal + "/inbox");
|
response.appendHrefProperty("C:schedule-inbox-URL", "/users/" + actualPrincipal + "/inbox");
|
||||||
@ -1300,7 +1337,8 @@ public class CaldavConnection extends AbstractConnection {
|
|||||||
currentElement = streamReader.getLocalName();
|
currentElement = streamReader.getLocalName();
|
||||||
if ("prop".equals(currentElement)) {
|
if ("prop".equals(currentElement)) {
|
||||||
inProperties = true;
|
inProperties = true;
|
||||||
} else if ("calendar-multiget".equals(currentElement)) {
|
} else if ("calendar-multiget".equals(currentElement)
|
||||||
|
|| "addressbook-multiget".equals(currentElement)) {
|
||||||
isMultiGet = true;
|
isMultiGet = true;
|
||||||
} else if (inProperties) {
|
} else if (inProperties) {
|
||||||
properties.add(currentElement);
|
properties.add(currentElement);
|
||||||
@ -1455,7 +1493,7 @@ public class CaldavConnection extends AbstractConnection {
|
|||||||
|
|
||||||
|
|
||||||
public void startMultistatus() throws IOException {
|
public void startMultistatus() throws IOException {
|
||||||
writer.write("<D:multistatus xmlns:D=\"DAV:\" xmlns:C=\"urn:ietf:params:xml:ns:caldav\">");
|
writer.write("<D:multistatus xmlns:D=\"DAV:\" xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:E=\"urn:ietf:params:xml:ns:carddav\">");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startResponse(String href) throws IOException {
|
public void startResponse(String href) throws IOException {
|
||||||
@ -1479,6 +1517,15 @@ public class CaldavConnection extends AbstractConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void appendContactData(String vcard) throws IOException {
|
||||||
|
if (vcard != null && vcard.length() > 0) {
|
||||||
|
writer.write("<E:address-data>");
|
||||||
|
writer.write(StringUtil.xmlEncode(vcard));
|
||||||
|
writer.write("</E:address-data>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void appendHrefProperty(String propertyName, String propertyValue) throws IOException {
|
public void appendHrefProperty(String propertyName, String propertyValue) throws IOException {
|
||||||
appendProperty(propertyName, null, "<D:href>" + URIUtil.encodePath(StringUtil.xmlEncode(propertyValue)) + "</D:href>");
|
appendProperty(propertyName, null, "<D:href>" + URIUtil.encodePath(StringUtil.xmlEncode(propertyValue)) + "</D:href>");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user