Skip to content

Commit

Permalink
Attempt to provide interoperability with SOGO
Browse files Browse the repository at this point in the history
  • Loading branch information
mstilkerich committed Sep 15, 2020
1 parent 7fd23ee commit a62f6e2
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/XmlElements/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,40 @@ public static function xmlDeserialize(\Sabre\Xml\Reader $reader): Response
throw new XmlParseException("DAV:response contains no DAV:href child");
}

if (isset($status)) {
/* By RFC 6578, there must be either a status OR a propstat child element.
*
* In practice however, we see the following uncompliances:
*
* Sabre/DAV always adds a propstat member, so for a 404 status, we will get an additional propstat with a
* pseudo status <d:status>HTTP/1.1 418 I'm a teapot</d:status>.
*
* SOGO on the other hand adds a status for answers where only a propstat is expected (new or changed items).
*
* To enable interoperability, we apply the following heuristic:
*
* 1) If we have a 404 status child element -> ResponseStatus
* 2) If we have a propstat element -> ResponsePropstat
* 3) If we have a status -> ResponseStatus
* 4) Error
*/
if (isset($status) && (stripos($status, " 404 ") !== false)) {
// Disable this exception for now as Sabre/DAV always inserts a propstat element to a response element
//if (count($propstat) > 0) {
// throw new XmlParseException("DAV:response contains both DAV:status and DAV:propstat children");
//}

return new ResponseStatus($hrefs, $status);
} else {
if (count($propstat) == 0) {
throw new XmlParseException("DAV:response contains neither DAV:status nor DAV:propstat children");
}
} elseif (count($propstat) > 0) {
if (count($hrefs) > 1) {
throw new XmlParseException("Propstat-type DAV:response contains multiple DAV:href children");
}

return new ResponsePropstat($hrefs[0], $propstat);
} elseif (isset($status)) {
return new ResponseStatus($hrefs, $status);
}

throw new XmlParseException("DAV:response contains neither DAV:status nor DAV:propstat children");
}
}

Expand Down

0 comments on commit a62f6e2

Please sign in to comment.