Implementing a Card- and CalDAV Client

2k views Asked by At

I was asked to develop a web-application that can talk to my company's Card-/CalDAV-Server (Kerio Connect). I've spent the past hours trying to find a suitable library but there doesn't seem to be one that is functional and still maintained. Milton looks great, but it's written in JAVA, which neither I nor my co-workers have worked with.

Instead, I'll probably have to write something myself, preferably in PHP or JavaScript. My question is; how? I really like how the entire thing is http-based, but aside from the RFC, there's very little documentation to be found. While I did manage to get a few of my curl-requests answered, others failed without me understanding why:

curl -X PROPFIND -u [email protected]:password -H "Content-Type: text/xml" -H "Depth: 1" --data "<propfind xmlns='DAV:'><prop><displayname /></prop></propfind>" http://webmail.domain.tld/carddav/users/domain.tld/.public

This works. I get a response containing "Public Folders (domain.tld)", which is, well, what I asked for.

curl -X PROPFIND -u [email protected]:password -H "Content-Type: text/xml" -H "Depth: 1" --data "<propfind xmlns='DAV:'><prop><addressbook-home-set xmlns="urn:ietf:params:xml:ns:carddav"/></prop></propfind>" http://webmail.domain.tld/carddav/users/domain.tld/.public

This one, on the other hand, returns 403 - Forbidden.

Both requests are probably wrong in some way - they're simply what I managed to piece together.

So how can I approach this? Would it be best to just read the RFC's, top to bottom? So far, they haven't been that helpful.

Edit:

I've read both articles on sabre.io. They did help me to some extend. However, I'm still not able to get the actual contact-data. I've managed to get a summary that contains UUID's for our shared address book, but how to use those UUID's, I have no idea.

Further, neither article goes into much detail as to how things are supposed to work. For example, first the CardDAV-related article states that the ctag must be stored for subsequent requests, then, only a few lines later, it mentions that the server might not support it at all. Further down, I learn that the ctag is supposedly a tag that lets me know if something has changed on the server; This is the purpose of the ctag. Every time anything in the address book changes, the ctag must also change. So..., what happens when my server doesn't support it? How do I know if it does? Requesting it simply yields a 403 - forbidden.

This is the request I'm using;

curl -X PROPFIND -u [email protected]:password -H "Content-Type: text/xml" --data "<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/"><d:prop><cs:getctag /></d:prop></d:propfind>" https://domain.tld/carddav/users/domain.tld/.public/

To get the aforementioned summary of our public address book, I used;

curl -X REPORT -u [email protected]:password -H "Content-Type: text/xml" --data "<c:addressbook-query xmlns:d='DAV:' xmlns:c='urn:ietf:params:xml:ns:carddav'><d:prop><c:address-data></c:address-data></d:prop></c:addressbook-query>" https://domain.tld/public-contacts/domain.tld/
1

There are 1 answers

0
hnh On

The SabreDAV website has a pretty good article on how to write CalDAV and CardDAV clients: Building a CalDAV client.

Besides, SabreDAV likely has a lot of the code which you would need to implement a DAV client in PHP. Other library implementations are listed on the CalConnect CalDAV website.