ranguard / text-vcard

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

Add big warning about probable data loss due to using this program #54

Open jidanni opened 6 years ago

jidanni commented 6 years ago

Please add a warning on vCard::AddressBook that by using this program one might lose 1/4 of their data or more.*

use strict;
use warnings FATAL => q{all};
use open qw/:std :encoding(utf8)/;
my $file = q(contacts.vcf);
open( my $fh, "<", $file ) or die;
my $I;
{ local $/; $I = <$fh>; }
printf "LENGTH IN:  %d\n", length $I;
use vCard::AddressBook;
my $address_book = vCard::AddressBook->new();
$address_book->load_string($I);
printf "LENGTH OUT: %d\n", length $address_book->as_string();

LENGTH IN: 36973 LENGTH OUT: 26285

*Based on tests with a typical contacts.vcf file produced via Google Contacts export.

The problem is anything unrecognized by the program is thrown away. Warn about that please.

In fact why not warn right away during execution that an unknown field has been encountered, and die, (if the user uses use warnings FATAL => q{all};).

See also #51.

ranguard commented 6 years ago

Hi,

Drop me a PR and I'll merge - I'm also happy for someone else to be co-maintain of this module as I'm not doing that great a job of maintaining it currently.

Leo

jidanni commented 6 years ago

Thanks but I have now given up, and just do

$ cat contact_grep
use strict;
use warnings FATAL => q{all};
use open qw/:std :encoding(utf8)/;
use Encode qw(decode_utf8);
die "$0: Usage: one argument" unless @ARGV == 1;
@ARGV = map { decode_utf8( $_, 1 ) } @ARGV;
my $file = q(/my/latest-contacts.vcf);
open( my $fh, "<", $file ) or die "$0: Can't open $file";
my ( $card, @cards );
while (<$fh>) {

    if (/^END:VCARD/) {
        push @cards, $card;
        undef $card;
        next;
    }
    next if /^VERSION:/;
    next if /^BEGIN:VCARD/;
    tr/\r//d;
    $card .= $_;
}
my @out;
for (@cards) {
    next unless /@ARGV/i;
    push @out, $_;
}
exit unless @out;
$_ = join "=" x 11 . "\n", @out;
print;