ranguard / text-vcard

Perl package to edit and create vCard(s) (RFC 2426)
22 stars 15 forks source link

export() destroys PHOTO #8

Closed jokrug closed 10 years ago

jokrug commented 10 years ago

I use code like this:

use Text::vCard::Addressbook;

# Get card name
my $card_file1 = $ARGV[0];

# Create Addressbook
my $address_book1 = Text::vCard::Addressbook->new({
 'source_file' => $card_file1,
});

my $vcf_file = $address_book1->export();

open(DATEI, ">cardfile_new.vcf") || die "Datei nicht gefunden";
print DATEI $vcf_file;
close(DATEI);

The input vcf-file contains a PHOTO: (This is only a small part of the file. If you need the full vcf for test, pse. mail.)

PHOTO;TYPE=PNG;ENCODING=b:iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+uBvAAAAA 3NCSVQICAjb4U/gAAAgAElEQVR4nJy8WZNl2VUmuNba05nu4GN4hEdGRkRGKlMppaqlQqIRqgJ JtDCTTN0YFFaNtRlYFdZYW8MvqGLoMoMnnnjiRQ8M3WZYg6iixKBGFKQQJJISVEipVEbOGRmTh 4f79TudaU+rH/b1G56RShXd28I8rh8/95yz1/7W9K21D1rbKaWstVJK64PW+u6de7/6q796dHR ERMfHJ/P5fDo5mU6niKiUarpjYwwRNU1TVVXTNAAYQhCkAABIICIAAABHBIDWWwDg07E+LoRIp yEiEa2+wqwQVqcxA8Z0NUTsuoaIlBJSSm0UAADEGKOUejgcAkDf98y8WCxmJ7MQYHNjo+u6um7 zPCfURVEsFsuiKKSWxpj5fF5V1cbGRtM0g7K6dOnSsp7/3M/93L/6Vz+OiN5bANBae+/FL/3SL ...

The exported file looks like this and the photos are not imported by my OwnCloud:

VERSION:3.0 PHOTO;TYPE=b,png: IHDRm��os��O� IDATx���Y�e�U&���ә��cx�GFFDF*S)���B��I�0�L�▒V��X�X[�/�b�2�'�x�E �fX���ĠF�$�TH�TF������;�iO����J���<�?���������Z�)���RJ������{����zttDD��'��|:9�N����j�cc 5MSUU�4▒B�H "G��[�ӱ>.�H�!"��¬V�1�t5D캆��RJm�▒��z8@��̼X,f'�sc�뺺n�<'�EQ,ˢ(��Ƙ�|^U���F�4���t�Ҳ�����ܿ�W?���[�Z{��/��/z���D�CB�Eu�ܹ�7o�u]�r� �[k��Z.�&ι▒cUU�9����{_�I�!��!�޻▒c����▒ ��>�~�#Efh= !�D��D`f$�1��B�▒�s�8wvv6���*.^�4▒�ڶ˲�P"b��m�fy���R�By���{�z��

jokrug commented 10 years ago

As there was no reaction on my issue, I debuged it myself. The following patch in Node.pm line 135 worked for me:

           # do this first
            if ( $self->is_type('b') or $self->is_type('base64') ) {

                $conf->{data}{value}
                    = MIME::Base64::decode( $conf->{data}{value} ) if (  $self->is_type('base64') );

                # mimic what goes on below
                @{$self}{ @{ $self->{field_order} } }
                    = ( $conf->{data}{value} );
            } else {

In a node PHOTO, TYPT=b is NOT base64.

ranguard commented 10 years ago

@jokrug sorry for not replying, this is actually being worked on at the moment - someone it looking at all of the encoding so I'll make sure he's aware of this for when we do a release

jokrug commented 10 years ago

Thank you for the answer. I'm looking forward to the next release. Best regards. jokrug

kablamo commented 10 years ago

@jokrug could you post the example vcard in a gist and link to that here? That would help with testing. Thanks!

jokrug commented 10 years ago

Am Mittwoch, 8. Januar 2014, 03:37:08 schrieb Eric Johnson:

@jokrug could you post the example vcard in a gist and link to that here? That would help with testing. Thanks!


Reply to this email directly or view it on GitHub: https://github.com/ranguard/text-vcard/issues/8#issuecomment-31824374

https://gist.github.com/fc3c81d4d181058947f9.git

I disabled the Base64::decode for ENCODING=B in Node.pm line 135 and it worked for me. I didn't notice any side effects, but my vcf-files use the ENCODING only for PHOTO type.

See this:

http://www.ietf.org/rfc/rfc2426.txt

... 3.1.4 PHOTO Type Definition

To: ietf-mime-directory@imc.org

Subject: Registration of text/directory MIME type PHOTO

Type name: PHOTO

Type purpose: To specify an image or photograph information that annotates some aspect of the object the vCard represents.

Type encoding: The encoding MUST be reset to "b" using the ENCODING parameter in order to specify inline, encoded binary data. If the value is referenced by a URI value, then the default encoding of 8bit is used and no explicit ENCODING parameter is needed.

Type value: A single value. The default is binary value. It can also be reset to uri value. The uri value can be used to specify a value outside of this MIME entity.

Type special notes: The type can include the type parameter "TYPE" to specify the graphic image format type. The TYPE parameter values MUST be one of the IANA registered image formats or a non-standard image format.

...

Btw. The vcf-files, I'm processing, are exports of my OwnCloud addressbook. I'm trying to create a set of perl scripts to clean-up my contacts: delete doubles, delete emtpy entries, merge cards, ...

Regards Joachim

ranguard commented 10 years ago

@jokrug if any of those scripts for cleaning up are generic enough and you want to create Text::vCard::Utils to put them in that would be great (but they might be too specific to you).