CalDAV and CardDAV synchronization to iCloud on UBports (Ubuntu Touch)
CalDAV and CardDAV are protocols to synchronize calendars and contacts with a remote server. At the moment, there is no carddav implementation directly accessible from the Ubuntu Touch graphical user-interface, so the only way to sync carddav is by using syncevolution + cron. The basic building blocks can be traced to here, here, here and here, but it took a little bit more before my phone was fully synced to iCloud.
Identify your user ID:
curl -s -X PROPFIND -u "$ICLOUD_LOGIN" -H "Depth: 0" --data "<propfind xmlns='DAV:'><prop><current-user-principal/></prop></propfind>" https://caldav.icloud.com/
After providing your app-specific password, you should get something like https://caldav.icloud.com/xxxNNNNNNNxxxxx/principal/
To reference the cluster where the actual calendars is stored:
curl -s -X PROPFIND -u "$ICLOUD_LOGIN" -H "Depth: 0" --data "<propfind xmlns='DAV:' xmlns:cd='urn:ietf:params:xml:ns:caldav'><prop><cd:calendar-home-set/></prop></propfind>"
https://caldav.icloud.com/xxxNNNNNNNxxxxx/principal/
Which should kick back something like https://pNN-caldav.icloud.com:443/xxxNNNNNNNxxxxx/calendars
You can list all the calendars from your iCoud account:
curl -s -X PROPFIND -u "$ICLOUD_LOGIN" -H "Depth: 1" --data "<propfind xmlns='DAV:'><prop><displayname/></prop></propfind>" https://pNN-caldav.icloud.com:443/xxxNNNNNNNxxxxx/calendars/
The CardDAV home contains the CardDAV collections (aka the 'address books'), not the vCards (which contain contacts and contact groups). If you redirect the previous steps to https://contacts.icloud.com, and follow the same sequence, you need to take one more hop.
This is how you eventually arrive at
iCloud_CalDAV_URL="https://pNN-caldav.icloud.com:443/xxxNNNNNNNxxxxx/calendars/home/"
iCloud_CardDAV_URL="https://pNN-contacts.icloud.com:443/xxxNNNNNNNxxxxx/carddavhome/card/"