Question

I'm looking the reliably transfer caldav entries from one server to another---sort of what imapcopy can do. I'm trying to use the Python caldav implementation, but I don't understand the protocol well enough to know how to migrate from one server to another. Is there an obvious way to do this?

Was it helpful?

Solution

I don't think there is a readymade tool which can do such migrations, but if you are fluent in Python and urllib2 it shouldn't be too hard to hack something up.

Do you want to transfer just one calendar, or all calendars with contents? Can you be more precise wrt the servers involved? Does it involve shared calendars?

The really hard part are meetings. Do you want to migrate such? If such are not a concern it's relatively straight forward:

If it's just one calendar, the basics are easy. In CalDAV a calendar is a WebDAV collection which contains 'iCalendar' resources. You can grab them as-is and transfer them to a different server. You just do a HTTP PROPFIND on the calendar URL to figure out the URLs of the resources contained within the collection. Than you make a simple HTTP GET to grab the iCalendar resource, and PUT it into the calendar on the target server. You don't even need to use a CalDAV library here (even a WebDAV library would be a bit overkill, you just need to parse the XML of the PROPFIND and use urllib2 for the requests).

Sample to grab just the resource URLs (events and todos) within a calendar: curl --verbose -u "login:pwd" -X PROPFIND -H "Depth: 1" --data "<propfind xmlns='DAV:'><prop/></propfind>" https://p00-caldav.icloud.com/xxx/calendars/work/

If the source server supports it (common), you could increase efficiency by using a multiget REPORT. If the target server supports it (rare), you could increase efficiency by using bulk-POST. Some servers (like iCloud) store attachments in a different place. This might require extra work.

If you also want to transfer the calendars, it's not too hard either, but more WebDAV is involved. You need to grab all the properties (names, colors) of the calendars by doing a PROPFIND on the calendar home (the URL containing all the calendars). The home of the CalDAV server can contain non-calendars, you can figure this one out by looking at the DAV:resourcetype property. For the calendars you can then create them on the target server using MKCOL or MKCALENDAR (those methods can take the properties you want to transfer).

Sample to grab names, colors etc of all calendars: curl --verbose -u "login:pwd" -X PROPFIND -H "Depth: 1" --data "<propfind xmlns='DAV:'><allprop/></propfind>" https://p00-caldav.icloud.com/xxx/calendars/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top