#!/usr/bin/perl -w # (c) 2005 Christoph Berg # All rights reserved. # This program is free software licensed under the terms of the GNU GPL v2. use strict; my ($card, $fn, @mail, %seen, @out); while (<>) { $card = 1 if /^BEGIN:VCARD/; next unless $card; $fn = $1 if /^FN:(.*)/; if (/^EMAIL;TYPE=internet(.*):(.*)/) { if ($1) { # ,pref unshift @mail, $2; } else { push @mail, $2; } } if (/^END:VCARD/) { if ($fn and @mail) { foreach my $m (@mail) { $m =~ /(.*)@/ or die; my $u = lc $1; if ($seen{$u}) { push @out, "alias $m $fn <$m>\n"; } else { push @out, "alias $u $fn <$m>\n"; $seen{$u} = 1; } } } undef $fn; undef @mail; $card = 0; } } map { print; } sort @out;