mukherjee78 / twisted-caldav

Ruby client for searching, creating, editing calendar and tasks.
MIT License
13 stars 13 forks source link

find_events() stops working w/ OwnCloud 9.x (REPORT Error) #2

Open ghost opened 7 years ago

ghost commented 7 years ago

I've updated to OwnCloud 9.1.4 and faced problems when trying to fetch CalDAV events via the find_events() method. The OwnCloud-Server sends a 400 (Bad Request) response with the following body:

<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:sabredav-version>3.0.9</s:sabredav-version>
  <s:exception>Sabre\DAV\Exception\BadRequest</s:exception>
  <s:message>A calendar-query REPORT on a calendar with a Depth: 0 is undefined. Set Depth to 1</s:message>
</d:error>

I fixed this by adding the necessary "Depth" HTTP request header in

lib/twisted-caldav/client.rb, line 67:

 req = Net::HTTP::Report.new(@url, initheader = {'Content-Type'=>'application/xml', 'Depth'=>'1'} )

Maybe you could add this extra header to your code as well - maybe this helps others who run into this problem.

ghost commented 7 years ago

And one more thing regarding find_events() and OwnCloud 9.x - the event parsing is also not working as expected and needs to be patched.

In client.rb, line 87 the CalDav events are being extracted as plain text

REXML::XPath.each( xml, '//c:calendar-data/', {"c"=>"urn:ietf:params:xml:ns:caldav"} ){|c| result << c.text }

The next line

r = Icalendar.parse(result)

fails to parse the text stored in "result", because a line-break is missing after "END:VCALENDAR".

So it's necessary to manually add a line-break and then it works again:

client.rb, line 87:

        REXML::XPath.each( xml, '//c:calendar-data/', {"c"=>"urn:ietf:params:xml:ns:caldav"} ){|c| result << "#{c.text}\n" }

Hope this helps.