diff --git a/lib/contact.php b/lib/contact.php index 27637fc5..dd88a35d 100644 --- a/lib/contact.php +++ b/lib/contact.php @@ -407,9 +407,28 @@ class Contact extends VObject\VCard implements IPIMObject { public function getPhoto() { $image = new \OCP\Image(); - if (isset($this->PHOTO) && $image->loadFromData($this->PHOTO->getValue())) { - return $image; - } elseif (isset($this->LOGO) && $image->loadFromData($this->LOGO->getValue())) { + if (isset($this->PHOTO)) { + $photo = $this->PHOTO; + } elseif (isset($this->LOGO)) { + $photo = $this->LOGO; + } else { + return null; + } + + $photovalue = $photo->getValue(); + + if ( $photo instanceof \Sabre\VObject\Property\Uri && substr($photovalue, 0, 5) === 'data:' ) { + $mimeType = substr($photovalue, 5, strpos($photovalue, ',')-5); + if (strpos($mimeType, ';')) { + $mimeType = substr($mimeType,0,strpos($mimeType, ';')); + } + + $photovalue = substr($photovalue, strpos($photovalue,',')+1); + + if ($image->loadFromBase64($photovalue)) { + return $image; + } + } elseif ($image->loadFromData($photovalue)) { return $image; } diff --git a/lib/utils/properties.php b/lib/utils/properties.php index 1c26f031..c7cd9501 100644 --- a/lib/utils/properties.php +++ b/lib/utils/properties.php @@ -333,8 +333,22 @@ Class Properties { $app = new App(); $vCard = $app->getContact($backendName, $addressBookId, $contactId); } + if (!isset($vCard->PHOTO)) { + return false; + } $image = new \OCP\Image(); - if (!isset($vCard->PHOTO) || !$image->loadFromBase64((string)$vCard->PHOTO)) { + $photostring = (string) $vCard->PHOTO; + + if ( $vCard->PHOTO instanceof \Sabre\VObject\Property\Uri && substr($photostring, 0, 5) === 'data:' ) { + $mimeType = substr($photostring, 5, strpos($photostring, ',')-5); + if (strpos($mimeType, ';')) { + $mimeType = substr($mimeType,0,strpos($mimeType, ';')); + } + $photostring = substr($photostring, strpos($photostring,',')+1); + } + + if (!$image->loadFromBase64($photostring)) { + #\OCP\Util::writeLog('contacts', __METHOD__.', photo: ' . print_r($photostring, true), \OCP\Util::DEBUG); return false; } }