sabre-io / vobject

:date: The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects
http://sabre.io/vobject/
BSD 3-Clause "New" or "Revised" License
569 stars 125 forks source link

Incorrect PHOTO conversion from 3.0 to 4.0 #457

Open blacksenator opened 5 years ago

blacksenator commented 5 years ago

RFC2426 shows the following example for 3.0:

PHOTO;ENCODING=b;TYPE=JPEG:,[base64-data]

For my project I´m actually handle only JPEGs in Version 3.0 vCards and adding this property in this way:

$vcard->add('PHOTO', $base64data, ['TYPE' => 'JPEG', 'ENCODING' => 'b']);

which works perfectly. After converting (for test purposes) this property shows:

PHOTO;VALUE=URI:data:image/jpeg;base64\,[base64-data]

which does not correspond to the RFC RFC6350:

PHOTO:data:image/jpeg;base64,[base64-data]
evert commented 5 years ago

There is a complication with the vcard specification in that it has conflicting information about this:

https://www.rfc-editor.org/errata/eid3845

Unfortunately this is therefore a little bit open to interpretation. I don't think the serialization that is used is necessarily wrong. It's simply impossible to do this right :(

blacksenator commented 5 years ago

According to your answer: What is the correct function parameter three for creating a Version 4.0 PHOTO property?

$vcard->add('PHOTO', $base64data, [ARRAY]);

I tried ['VALUE' => 'URI:data:image/jpeg;base64\'] but received:

Unsupported VALUE parameter for PHOTO property. You supplied "URI:data:image/jpeg;base64\"

I have not tried the keys TYPE and encoding - because this is obviously incorrect for version 4.0!

+++UPDATE+++ I found only this solution - looks not very smart:

$vcard->add('PHOTO', 'data:' . $mimetype . ';base64,' . base64_encode([$base64_data]));
respiranto commented 5 days ago

Note: This seems to be a duplicate of #382.