Page MenuHomePhorge

D4656.1775485605.diff
No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None

D4656.1775485605.diff

diff --git a/plugins/libkolab/lib/kolab_dav_client.php b/plugins/libkolab/lib/kolab_dav_client.php
--- a/plugins/libkolab/lib/kolab_dav_client.php
+++ b/plugins/libkolab/lib/kolab_dav_client.php
@@ -429,15 +429,18 @@
*/
public function folderCreate($location, $component, $properties = [])
{
- $ns = 'xmlns:d="DAV:"';
- $props = '';
+ [$props, $ns] = $this->folderPropertiesToXml($properties, 'xmlns:d="DAV:"');
if ($component == 'VCARD') {
$ns .= ' xmlns:c="urn:ietf:params:xml:ns:carddav"';
- $props = '<d:resourcetype><d:collection/><c:addressbook/></d:resourcetype>';
+ $props .= '<d:resourcetype><d:collection/><c:addressbook/></d:resourcetype>';
} else {
$ns .= ' xmlns:c="urn:ietf:params:xml:ns:caldav"';
- $props = '<d:resourcetype><d:collection/><c:calendar/></d:resourcetype>';
+ $props .= '<d:resourcetype><d:collection/><c:calendar/></d:resourcetype>'
+ // Note: Some clients, but also Cyrus by default allows everything in calendar folders,
+ // i.e. VEVENT, VTODO, VJOURNAL, VFREEBUSY, VAVAILABILITY, but we prefer a single-type folders,
+ // to keep tasks and event separated
+ . '<c:supported-calendar-component-set><c:comp name="' . $component . '"/></c:supported-calendar-component-set>';
}
$body = '<?xml version="1.0" encoding="utf-8"?>'
@@ -450,12 +453,7 @@
// Create the collection
$response = $this->request($location, 'MKCOL', $body);
- if (empty($response)) {
- return false;
- }
-
- // Update collection properties
- return $this->folderUpdate($location, $component, $properties);
+ return $response !== false;
}
/**
@@ -483,29 +481,35 @@
*/
public function folderUpdate($location, $component, $properties = [])
{
- $ns = 'xmlns:d="DAV:"';
- $props = '';
+ // Note: Changing resourcetype property is forbidden (at least by Cyrus)
- if ($component == 'VCARD') {
- $ns .= ' xmlns:c="urn:ietf:params:xml:ns:carddav"';
- // Resourcetype property is protected
- // $props = '<d:resourcetype><d:collection/><c:addressbook/></d:resourcetype>';
- } else {
- $ns .= ' xmlns:c="urn:ietf:params:xml:ns:caldav"';
- // Resourcetype property is protected
- // $props = '<d:resourcetype><d:collection/><c:calendar/></d:resourcetype>';
- /*
- // Note: These are set by Cyrus automatically for calendars
- . '<c:supported-calendar-component-set>'
- . '<c:comp name="VEVENT"/>'
- . '<c:comp name="VTODO"/>'
- . '<c:comp name="VJOURNAL"/>'
- . '<c:comp name="VFREEBUSY"/>'
- . '<c:comp name="VAVAILABILITY"/>'
- . '</c:supported-calendar-component-set>';
- */
+ [$props, $ns] = $this->folderPropertiesToXml($properties, 'xmlns:d="DAV:"');
+
+ if (empty($props)) {
+ return true;
}
+ $body = '<?xml version="1.0" encoding="utf-8"?>'
+ . '<d:propertyupdate ' . $ns . '>'
+ . '<d:set>'
+ . '<d:prop>' . $props . '</d:prop>'
+ . '</d:set>'
+ . '</d:propertyupdate>';
+
+ $response = $this->request($location, 'PROPPATCH', $body);
+
+ // TODO: Should we make sure "200 OK" status is set for all requested properties?
+
+ return $response !== false;
+ }
+
+ /**
+ * Parse folder properties input into XML string to use in a request
+ */
+ protected function folderPropertiesToXml($properties, $ns = '')
+ {
+ $props = '';
+
foreach ($properties as $name => $value) {
if ($name == 'name') {
$props .= '<d:displayname>' . htmlspecialchars($value, ENT_XML1, 'UTF-8') . '</d:displayname>';
@@ -525,22 +529,7 @@
}
}
- if (empty($props)) {
- return true;
- }
-
- $body = '<?xml version="1.0" encoding="utf-8"?>'
- . '<d:propertyupdate ' . $ns . '>'
- . '<d:set>'
- . '<d:prop>' . $props . '</d:prop>'
- . '</d:set>'
- . '</d:propertyupdate>';
-
- $response = $this->request($location, 'PROPPATCH', $body);
-
- // TODO: Should we make sure "200 OK" status is set for all requested properties?
-
- return $response !== false;
+ return [$props, $ns];
}
/**

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 6, 2:26 PM (1 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18837847
Default Alt Text
D4656.1775485605.diff (4 KB)

Event Timeline