mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 00:17:03 +03:00
Improvements for #79
This commit is contained in:
parent
b4fefc1532
commit
14c8e81332
3 changed files with 28 additions and 64 deletions
|
|
@ -223,7 +223,7 @@ class AddressBook extends \RainLoop\Providers\AbstractProvider
|
||||||
{
|
{
|
||||||
$iCount = 0;
|
$iCount = 0;
|
||||||
|
|
||||||
if (\class_exists('Sabre\DAV\Client') && $this->IsActive() && \is_string($sVcfData))
|
if ($this->IsActive() && \is_string($sVcfData))
|
||||||
{
|
{
|
||||||
$sVcfData = \trim($sVcfData);
|
$sVcfData = \trim($sVcfData);
|
||||||
if ("\xef\xbb\xbf" === \substr($sVcfData, 0, 3))
|
if ("\xef\xbb\xbf" === \substr($sVcfData, 0, 3))
|
||||||
|
|
|
||||||
|
|
@ -189,11 +189,6 @@ class Contact implements \JsonSerializable
|
||||||
{
|
{
|
||||||
$this->UpdateDependentValues();
|
$this->UpdateDependentValues();
|
||||||
|
|
||||||
if (!\class_exists('Sabre\DAV\Client'))
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("\xef\xbb\xbf" === \substr($sPreVCard, 0, 3))
|
if ("\xef\xbb\xbf" === \substr($sPreVCard, 0, 3))
|
||||||
{
|
{
|
||||||
$sPreVCard = \substr($sPreVCard, 3);
|
$sPreVCard = \substr($sPreVCard, 3);
|
||||||
|
|
@ -509,11 +504,6 @@ class Contact implements \JsonSerializable
|
||||||
|
|
||||||
$this->Properties = array();
|
$this->Properties = array();
|
||||||
|
|
||||||
if (!\class_exists('Sabre\DAV\Client'))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($sEtag))
|
if (!empty($sEtag))
|
||||||
{
|
{
|
||||||
$this->Etag = $sEtag;
|
$this->Etag = $sEtag;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,10 @@ class Client
|
||||||
{
|
{
|
||||||
// public $__UrlPath__;
|
// public $__UrlPath__;
|
||||||
|
|
||||||
|
const
|
||||||
|
NS_DAV = 'urn:DAV',
|
||||||
|
NS_CARDDAV = 'urn:ietf:params:xml:ns:carddav';
|
||||||
|
|
||||||
protected $baseUri;
|
protected $baseUri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -150,20 +154,31 @@ class Client
|
||||||
|
|
||||||
$responseXML->registerXPathNamespace($ns, 'urn:DAV');
|
$responseXML->registerXPathNamespace($ns, 'urn:DAV');
|
||||||
foreach ($responseXML->xpath("{$ns}:response") as $response) {
|
foreach ($responseXML->xpath("{$ns}:response") as $response) {
|
||||||
$response->registerXPathNamespace($ns, 'urn:DAV');
|
|
||||||
$href = $response->xpath("{$ns}:href");
|
|
||||||
$href = (string) $href[0];
|
|
||||||
|
|
||||||
$properties = array();
|
$properties = array();
|
||||||
|
$response->registerXPathNamespace($ns, 'urn:DAV');
|
||||||
foreach ($response->xpath("{$ns}:propstat") as $propStat) {
|
foreach ($response->xpath("{$ns}:propstat") as $propStat) {
|
||||||
|
// Parse all WebDAV properties
|
||||||
|
$propList = array();
|
||||||
$propStat->registerXPathNamespace($ns, 'urn:DAV');
|
$propStat->registerXPathNamespace($ns, 'urn:DAV');
|
||||||
$status = $propStat->xpath("{$ns}:status");
|
foreach ($propStat->xpath("{$ns}:prop") as $prop) {
|
||||||
list($httpVersion, $statusCode, $message) = \explode(' ', (string)$status[0], 3);
|
foreach ($prop->xpath("*") as $element) {
|
||||||
|
$propertyName = self::toClarkNotation($element);
|
||||||
$properties[$statusCode] = static::parseProperties(\dom_import_simplexml($propStat));
|
if ('{DAV:}resourcetype' === $propertyName) {
|
||||||
|
$propList[$propertyName] = [];
|
||||||
|
foreach ($element->xpath("*") as $resourcetype) {
|
||||||
|
$propList[$propertyName][] = self::toClarkNotation($resourcetype);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$propList[$propertyName] = (string) $element;
|
||||||
|
// $propList[$propertyName] = \dom_import_simplexml($element)->textContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list($httpVersion, $statusCode, $message) = \explode(' ', $propStat->children('urn:DAV')->status, 3);
|
||||||
|
$properties[$statusCode] = $propList;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[$href] = $properties;
|
$result[(string) $response->children('urn:DAV')->href] = $properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 === $depth) {
|
if (0 === $depth) {
|
||||||
|
|
@ -188,53 +203,12 @@ class Client
|
||||||
* Elements encoded with the urn:DAV namespace will
|
* Elements encoded with the urn:DAV namespace will
|
||||||
* be returned as if they were in the DAV: namespace. This is to avoid
|
* be returned as if they were in the DAV: namespace. This is to avoid
|
||||||
* compatibility problems.
|
* compatibility problems.
|
||||||
*
|
|
||||||
* This function will return null if a nodetype other than an Element is passed.
|
|
||||||
*/
|
*/
|
||||||
public static function toClarkNotation(\DOMNode $dom) : ?string
|
public static function toClarkNotation(\SimpleXMLElement $element) : string
|
||||||
{
|
{
|
||||||
// Mapping back to the real namespace, in case it was dav
|
// Mapping back to the real namespace, in case it was dav
|
||||||
// Mapping to clark notation
|
// Mapping to clark notation
|
||||||
return XML_ELEMENT_NODE === $dom->nodeType
|
$ns = \array_values($element->getNamespaces())[0];
|
||||||
? '{' . ('urn:DAV' == $dom->namespaceURI ? 'DAV:' : $dom->namespaceURI) . '}' . $dom->localName
|
return '{' . ('urn:DAV' == $ns ? 'DAV:' : $ns) . '}' . $element->getName();
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses all WebDAV properties out of a DOM Element
|
|
||||||
*
|
|
||||||
* Generally WebDAV properties are enclosed in {DAV:}prop elements. This
|
|
||||||
* method helps by going through all these and pulling out the actual
|
|
||||||
* propertynames, making them array keys and making the property values,
|
|
||||||
* well.. the array values.
|
|
||||||
*
|
|
||||||
* If no value was given (self-closing element) null will be used as the
|
|
||||||
* value. This is used in for example PROPFIND requests.
|
|
||||||
*
|
|
||||||
* When any of these properties are found, the fromDOMElement() method will be
|
|
||||||
* (statically) called. The result of this method is used as the value.
|
|
||||||
*/
|
|
||||||
protected static function parseProperties(\DOMElement $parentNode) : array
|
|
||||||
{
|
|
||||||
$propList = array();
|
|
||||||
foreach ($parentNode->childNodes as $propNode) {
|
|
||||||
if ('{DAV:}prop' === self::toClarkNotation($propNode)) {
|
|
||||||
foreach ($propNode->childNodes as $propNodeData) {
|
|
||||||
/* If there are no elements in here, we actually get 1 text node, this special case is dedicated to netdrive */
|
|
||||||
if (XML_ELEMENT_NODE == $propNodeData->nodeType) {
|
|
||||||
$propertyName = self::toClarkNotation($propNodeData);
|
|
||||||
if ('{DAV:}resourcetype' === $propertyName) {
|
|
||||||
$propList[$propertyName] = [];
|
|
||||||
foreach ($propNodeData->childNodes as $resourcetype) {
|
|
||||||
$propList[$propertyName][] = self::toClarkNotation($resourcetype);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$propList[$propertyName] = $propNodeData->textContent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $propList;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue