#!/usr/bin/perl -w
#by Torben Menke 2008-02-29
#http://www.entorb.net
# export a kmail-addressbook to a text file with the format:
# Name <eMail>

use warnings;
use strict;
use Data::Dumper;
my ($s,$i);

my @list;
my $output = '/home/torben/adressen/addressbook-email-export.txt';
my @files = ('/home/torben/.kde/share/apps/kabc/privat.vcf',
'/home/torben/.kde/share/apps/kabc/iapp.vcf');
foreach my $file (@files) {
#my $file = '/home/torben/.kde/share/apps/kabc/iapp.vcf';
open (FILE, "< $file") or die $!;
my @cont = <FILE>;
close FILE;

@cont = grep {m/^(BEGIN:VCARD|EMAIL|N:)/} @cont;
#EMAIL;TYPE= -> E:
@cont = map {s/^EMAIL[^:]*:/E:/;$_} @cont;

# remove first BEGIN:VCARD
shift @cont;

# split by BEGIN:VCARD
$s = join '',@cont;
# remove linefeeds (\r) if they exis
$s =~ s/\r//g;
@cont = split /BEGIN:VCARD/, $s;
# remove all without email
@cont = grep {m/^E:/m} @cont;

foreach my $contact (@cont) {
$contact =~ m/N:([^;]*);([^;]*)/m or next;
my $name = "$2 $1";
my @l = split "\n", $contact;
@l = grep {m/^E:/} @l;
foreach my $line (@l) {
$line =~ s/E:\s*(\S+)\s*/$name <$1>/ and push @list,$line;
}
}
#print Dumper @list and die;
} # end foreach file



open (OUT, "> $output") or die $!;
@list = sort grep {not m/ZZZ /i} @list;
print OUT join "\n", @list;
close OUT;

print "",(1+$#list), " eMails exportet to $output.\n";

Hope you found what you where looking for. Feel free to drop me a line
Torben