Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/VCardConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,17 @@ protected function convertBinaryToUri(Component\VCard $output, Binary $newProper
if (isset($parameters['TYPE'])) {
$newTypes = [];
foreach ($parameters['TYPE']->getParts() as $typePart) {
$format = strtoupper((string) $typePart);
// Some clients write the MIME type (TYPE=image/jpeg) instead of the short name.
if (str_starts_with($format, 'IMAGE/')) {
$format = substr($format, strlen('IMAGE/'));
}
if (in_array(
strtoupper((string) $typePart),
['JPEG', 'PNG', 'GIF'],
$format,
['JPEG', 'PNG', 'GIF', 'WEBP'],
true
)) {
$mimeType = 'image/'.strtolower((string) $typePart);
$mimeType = 'image/'.strtolower($format);
} else {
$newTypes[] = $typePart;
}
Expand Down Expand Up @@ -336,7 +341,7 @@ protected function convertUriToBinary(Component\VCard $output, Uri $newProperty)
unset($value);

$newProperty['ENCODING'] = 'b';
switch ($mimeType) {
switch (strtolower($mimeType)) {
case 'image/jpeg':
$newProperty['TYPE'] = 'JPEG';
break;
Expand All @@ -346,6 +351,9 @@ protected function convertUriToBinary(Component\VCard $output, Uri $newProperty)
case 'image/gif':
$newProperty['TYPE'] = 'GIF';
break;
case 'image/webp':
$newProperty['TYPE'] = 'WEBP';
break;
}

return $newProperty;
Expand Down
8 changes: 8 additions & 0 deletions tests/VObject/VCardConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function testConvert30to40(): void
ITEM1.X-ABLABEL:CustomLabel
PHOTO;ENCODING=b;TYPE=JPEG,HOME:Zm9v
PHOTO;ENCODING=b;TYPE=GIF:Zm9v
PHOTO;ENCODING=b;TYPE=WEBP:Zm9v
PHOTO;ENCODING=b;TYPE=image/webp:Zm9v
PHOTO;X-PARAM=FOO;ENCODING=b;TYPE=PNG:Zm9v
PHOTO;VALUE=URI:http://example.org/foo.png
X-ABShowAs:COMPANY
Expand All @@ -39,6 +41,8 @@ public function testConvert30to40(): void
ITEM1.X-ABLABEL:CustomLabel
PHOTO;TYPE=HOME:data:image/jpeg;base64,Zm9v
PHOTO:data:image/gif;base64,Zm9v
PHOTO:data:image/webp;base64,Zm9v
PHOTO:data:image/webp;base64,Zm9v
PHOTO;X-PARAM=FOO:data:image/png;base64,Zm9v
PHOTO:http://example.org/foo.png
KIND:ORG
Expand Down Expand Up @@ -194,6 +198,8 @@ public function testConvert40to30(): void
TEL;PREF=1;TYPE=HOME:+1 555 666 777
PHOTO:data:image/jpeg;base64,Zm9v
PHOTO:data:image/gif,foo
PHOTO:data:image/webp;base64,Zm9v
PHOTO:data:image/WEBP;base64,Zm9v
PHOTO;X-PARAM=FOO:data:image/png;base64,Zm9v
PHOTO:http://example.org/foo.png
KIND:ORG
Expand All @@ -208,6 +214,8 @@ public function testConvert40to30(): void
TEL;TYPE=PREF,HOME:+1 555 666 777
PHOTO;ENCODING=b;TYPE=JPEG:Zm9v
PHOTO;ENCODING=b;TYPE=GIF:Zm9v
PHOTO;ENCODING=b;TYPE=WEBP:Zm9v
PHOTO;ENCODING=b;TYPE=WEBP:Zm9v
PHOTO;ENCODING=b;TYPE=PNG;X-PARAM=FOO:Zm9v
PHOTO;VALUE=URI:http://example.org/foo.png
X-ABSHOWAS:COMPANY
Expand Down