From f53ff8edecc17aa9c2645427d2460577474a0c78 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 12 Oct 2022 16:19:31 +0200 Subject: [PATCH] Fixed folders discovery, fixed xml formatting in debug log --- plugins/libkolab/lib/kolab_dav_client.php | 50 ++++++++++++++++------ plugins/libkolab/lib/kolab_storage_dav.php | 6 +++ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/plugins/libkolab/lib/kolab_dav_client.php b/plugins/libkolab/lib/kolab_dav_client.php index ee33d8d6..d9ae88da 100644 --- a/plugins/libkolab/lib/kolab_dav_client.php +++ b/plugins/libkolab/lib/kolab_dav_client.php @@ -120,7 +120,12 @@ class kolab_dav_client */ public function discover($component = 'VEVENT') { -/* + $roots = [ + 'VEVENT' => 'calendars', + 'VTODO' => 'calendars', + 'VCARD' => 'addressbooks', + ]; + $path = parse_url($this->url, PHP_URL_PATH); $body = '' @@ -130,7 +135,7 @@ class kolab_dav_client . '' . ''; - $response = $this->request('/calendars', 'PROPFIND', $body); + $response = $this->request('/' . $roots[$component], 'PROPFIND', $body); $elements = $response->getElementsByTagName('response'); @@ -153,14 +158,25 @@ class kolab_dav_client . ''; $response = $this->request($principal_href, 'PROPFIND', $body); -*/ - $roots = [ - 'VEVENT' => 'calendars', - 'VTODO' => 'calendars', - 'VCARD' => 'addressbooks', - ]; - $principal_href = '/' . $roots[$component] . '/' . rawurlencode($this->user); + $elements = $response->getElementsByTagName('response'); + + foreach ($elements as $element) { + foreach ($element->getElementsByTagName('prop') as $prop) { + $root_href = $prop->nodeValue; + break; + } + } + + if (!empty($root_href)) { + if ($path && strpos($root_href, $path) === 0) { + $root_href = substr($root_href, strlen($path)); + } + } + else { + // Kolab iRony's calendar root + $root_href = '/' . $roots[$component] . '/' . rawurlencode($this->user); + } $body = '' . '' @@ -173,7 +189,7 @@ class kolab_dav_client . '' . ''; - $response = $this->request($principal_href, 'PROPFIND', $body); + $response = $this->request($root_href, 'PROPFIND', $body); if (empty($response)) { return false; @@ -363,12 +379,13 @@ class kolab_dav_client if (stripos($body, 'formatOutput = true; + $doc->preserveWhiteSpace = false; + if (!$doc->loadXML($body)) { throw new Exception("Failed to parse XML"); } - $doc->formatOutput = true; - $body = $doc->saveXML(); } @@ -414,12 +431,21 @@ class kolab_dav_client } } + $types = []; + if ($type_element = $element->getElementsByTagName('resourcetype')->item(0)) { + foreach ($type_element->childNodes as $node) { + $_type = explode(':', $node->nodeName); + $types[] = count($_type) > 1 ? $_type[1] : $_type[0]; + } + } + return [ 'href' => $href, 'name' => $name, 'ctag' => $ctag, 'color' => $color, 'type' => $component, + 'resource_type' => $types, ]; } diff --git a/plugins/libkolab/lib/kolab_storage_dav.php b/plugins/libkolab/lib/kolab_storage_dav.php index 82e3d938..ce064178 100644 --- a/plugins/libkolab/lib/kolab_storage_dav.php +++ b/plugins/libkolab/lib/kolab_storage_dav.php @@ -72,6 +72,12 @@ class kolab_storage_dav if (is_array($folders)) { foreach ($folders as $idx => $folder) { + // Exclude some special folders + if (in_array('schedule-inbox', $folder['resource_type']) || in_array('schedule-outbox', $folder['resource_type'])) { + unset($folders[$idx]); + continue; + } + $folders[$idx] = new kolab_storage_dav_folder($this->dav, $folder, $type); } }