#!/usr/bin/perl -w # # A sample vCard reader. Read a single vcard or a whole addressbook. # # Copyright (C) Alessandro Dotti Contra # # Released under the terms of the GNU GPL version 2. # # Revision 0.1 # ============================================================================= use Text::vCard; use Text::vCard::Node; use Text::vCard::Addressbook; # ============================================================================= if(scalar(@ARGV) != 1) { die "usage: vcfreader \n"; } my $SOURCE = $ARGV[0]; # # read vcard # my $addressbook = Text::vCard::Addressbook->new( { 'source_file' => $SOURCE, } ); foreach my $vcard($addressbook->vcards()) { # # print name and title # my $name = $vcard->get({ 'node_type' => 'name' }); if($name) { print $name->[0]->prefixes() . " " if $name->[0]->prefixes(); print $name->[0]->given() . " "; print $name->[0]->family() . " "; print "[" . $vcard->title() . "]" if $vcard->title(); } else { print $vcard->fullname(); } print "\n"; # # print organizations and role # my $organizations = $vcard->get({ 'node_type' => 'ORG' }); foreach my $organization(@{ $organizations }) { print $organization->name(); my $units = $organization->unit(); foreach my $unit(@{ $units }) { print " ($unit)\n"; } print "\n"; } print "(" . $vcard->role() . ")\n" if $vcard->role(); print "\n"; # # print addresses # my $addresses = $vcard->get({ 'node_type' => 'addresses', }); if ($addresses) { print "Addresses:\n"; foreach my $address(@{ $addresses }) { my @types = $address->types(); foreach my $type(sort @types) { print "$type "; } print ": "; print $address->po_box() if $address->po_box(); print " " . $address->extended() if $address->extended(); print " " . $address->street() if $address->street(); print " " . $address->city() if $address->city(); print " (" . $address->region() . ")" if $address->region(); print " " . $address->post_code() if $address->post_code(); print " " . $address->country() if $address->country(); print "\n"; } print "\n"; } # # print telephone numbers # my $phones = $vcard->get({ 'node_type' => 'phones', }); if($phones) { print "Phones\n"; foreach my $phone(@{ $phones }) { my @types = $phone->types(); foreach my $type(sort @types) { print "$type "; } print ": "; print $phone->value(); print "\n"; } print "\n"; } # # print emails # my $emails = $vcard->get({ 'node_type' => 'email' }); if($emails) { print "e-mails\n"; foreach my $email(@{ $emails }) { print $email->value() . "\n"; } print "\n"; } # # print urls # my $urls = $vcard->get({ 'node_type' => 'url' }); if($urls) { print "urls\n"; foreach my $url(@{ $urls }) { print $url->value() . "\n"; } print "\n"; } print "-" x 80, "\n"; } exit 0;