diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2012-10-13 22:03:44 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2012-10-13 22:04:22 +0200 |
commit | 183cc22501b75ab8819971f70b88dbc010026ac1 (patch) | |
tree | 878db72be46fe5394f8615c2bcf579d9e943d76b /3rdparty/Sabre/CardDAV/Plugin.php | |
parent | 5713dcfd11f6d0f57b6302bedeb22c18df5d73bb (diff) | |
download | nextcloud-server-183cc22501b75ab8819971f70b88dbc010026ac1.tar.gz nextcloud-server-183cc22501b75ab8819971f70b88dbc010026ac1.zip |
Update SabreDAV to 1.7.1
Diffstat (limited to '3rdparty/Sabre/CardDAV/Plugin.php')
-rwxr-xr-x | 3rdparty/Sabre/CardDAV/Plugin.php | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/3rdparty/Sabre/CardDAV/Plugin.php b/3rdparty/Sabre/CardDAV/Plugin.php index 96def6dd96b..12bccaec4fb 100755 --- a/3rdparty/Sabre/CardDAV/Plugin.php +++ b/3rdparty/Sabre/CardDAV/Plugin.php @@ -1,5 +1,7 @@ <?php +use Sabre\VObject; + /** * CardDAV plugin * @@ -48,6 +50,7 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { /* Events */ $server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties')); + $server->subscribeEvent('afterGetProperties', array($this, 'afterGetProperties')); $server->subscribeEvent('updateProperties', array($this, 'updateProperties')); $server->subscribeEvent('report', array($this,'report')); $server->subscribeEvent('onHTMLActionsPanel', array($this,'htmlActionsPanel')); @@ -153,10 +156,6 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { if (is_resource($val)) $val = stream_get_contents($val); - // Taking out \r to not screw up the xml output - //$returnedProperties[200][$addressDataProp] = str_replace("\r","", $val); - // The stripping of \r breaks the Mail App in OSX Mountain Lion - // this is fixed in master, but not backported. /Tanghus $returnedProperties[200][$addressDataProp] = $val; } @@ -190,7 +189,7 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { * @param array $mutations * @param array $result * @param Sabre_DAV_INode $node - * @return void + * @return bool */ public function updateProperties(&$mutations, &$result, $node) { @@ -272,7 +271,7 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { $properties = array_keys(Sabre_DAV_XMLUtil::parseProperties($dom->firstChild)); - $hrefElems = $dom->getElementsByTagNameNS('urn:DAV','href'); + $hrefElems = $dom->getElementsByTagNameNS('DAV:','href'); $propertyList = array(); foreach($hrefElems as $elem) { @@ -282,9 +281,12 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { } + $prefer = $this->server->getHTTPPRefer(); + $this->server->httpResponse->sendStatus(207); $this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8'); - $this->server->httpResponse->sendBody($this->server->generateMultiStatus($propertyList)); + $this->server->httpResponse->setHeader('Vary','Brief,Prefer'); + $this->server->httpResponse->sendBody($this->server->generateMultiStatus($propertyList, $prefer['return-minimal'])); } @@ -348,9 +350,9 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { try { - $vobj = Sabre_VObject_Reader::read($data); + $vobj = VObject\Reader::read($data); - } catch (Sabre_VObject_ParseException $e) { + } catch (VObject\ParseException $e) { throw new Sabre_DAV_Exception_UnsupportedMediaType('This resource only supports valid vcard data. Parse error: ' . $e->getMessage()); @@ -360,6 +362,10 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { throw new Sabre_DAV_Exception_UnsupportedMediaType('This collection can only support vcard objects.'); } + if (!isset($vobj->UID)) { + throw new Sabre_DAV_Exception_BadRequest('Every vcard must have an UID.'); + } + } @@ -424,9 +430,12 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { } + $prefer = $this->server->getHTTPPRefer(); + $this->server->httpResponse->sendStatus(207); $this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8'); - $this->server->httpResponse->sendBody($this->server->generateMultiStatus($result)); + $this->server->httpResponse->setHeader('Vary','Brief,Prefer'); + $this->server->httpResponse->sendBody($this->server->generateMultiStatus($result, $prefer['return-minimal'])); } @@ -440,7 +449,7 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { */ public function validateFilters($vcardData, array $filters, $test) { - $vcard = Sabre_VObject_Reader::read($vcardData); + $vcard = VObject\Reader::read($vcardData); if (!$filters) return true; @@ -616,6 +625,30 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin { } /** + * This event is triggered after webdav-properties have been retrieved. + * + * @return bool + */ + public function afterGetProperties($uri, &$properties) { + + // If the request was made using the SOGO connector, we must rewrite + // the content-type property. By default SabreDAV will send back + // text/x-vcard; charset=utf-8, but for SOGO we must strip that last + // part. + if (!isset($properties[200]['{DAV:}getcontenttype'])) + return; + + if (strpos($this->server->httpRequest->getHeader('User-Agent'),'Thunderbird')===false) { + return; + } + + if (strpos($properties[200]['{DAV:}getcontenttype'],'text/x-vcard')===0) { + $properties[200]['{DAV:}getcontenttype'] = 'text/x-vcard'; + } + + } + + /** * This method is used to generate HTML output for the * Sabre_DAV_Browser_Plugin. This allows us to generate an interface users * can use to create new calendars. |