From fa6c25708455d061da20178d021674ebb661c297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Mon, 17 Dec 2018 12:45:07 +0100 Subject: [PATCH] Allow URI as data for vcard PHOTO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/dav/lib/CardDAV/ImageExportPlugin.php | 1 + apps/dav/lib/CardDAV/PhotoCache.php | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/dav/lib/CardDAV/ImageExportPlugin.php b/apps/dav/lib/CardDAV/ImageExportPlugin.php index cac8e79574..7aa95922f1 100644 --- a/apps/dav/lib/CardDAV/ImageExportPlugin.php +++ b/apps/dav/lib/CardDAV/ImageExportPlugin.php @@ -108,6 +108,7 @@ class ImageExportPlugin extends ServerPlugin { $response->setBody($file->getContent()); } catch (NotFoundException $e) { + var_dump($e); $response->setStatus(404); } diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php index 0029af7bff..2f3cc66f1d 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -30,6 +30,7 @@ use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFolder; use Sabre\CardDAV\Card; use Sabre\VObject\Property\Binary; +use Sabre\VObject\Property\Uri; use Sabre\VObject\Reader; class PhotoCache { @@ -193,12 +194,13 @@ class PhotoCache { } $photo = $vObject->PHOTO; - $type = $this->getType($photo); - $val = $photo->getValue(); + + // handle data URI. e.g PHOTO;VALUE=URI:data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE if ($photo->getValueType() === 'URI') { $parsed = \Sabre\URI\parse($val); - //only allow data:// + + // only allow data:// if ($parsed['scheme'] !== 'data') { return false; } @@ -206,6 +208,9 @@ class PhotoCache { list($type,) = explode(';', $parsed['path']); } $val = file_get_contents($val); + } else { + // get type if binary data + $type = $this->getBinaryType($photo); } $allowedContentTypes = [ @@ -240,7 +245,7 @@ class PhotoCache { * @param Binary $photo * @return string */ - private function getType(Binary $photo) { + private function getBinaryType(Binary $photo) { $params = $photo->parameters(); if (isset($params['TYPE']) || isset($params['MEDIATYPE'])) { /** @var Parameter $typeParam */