X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=contrib%2Fvcard2abook.pl;fp=contrib%2Fvcard2abook.pl;h=296a18c70b97b1e279488226d6de8e5c92308914;hb=9d28f71348269e7075d0ff5c0b7ae4e05f358304;hp=0000000000000000000000000000000000000000;hpb=c0b0c6c7a0971525558239e544212589fbbac58b;p=pkg%2Fabook.git diff --git a/contrib/vcard2abook.pl b/contrib/vcard2abook.pl new file mode 100755 index 0000000..296a18c --- /dev/null +++ b/contrib/vcard2abook.pl @@ -0,0 +1,91 @@ +#!/usr/bin/perl -w +my $timestamp= "Time-stamp: \"vcard2abook.pl was last updated on Sun, 17 Dec 2000 10:34am\""; + +#==============================================================================* +# vcard2abook.pl by jeff covey * +# * +# this script has two main features: * +# * +# 1. it converts a file containing addressbook entries in vcard format to * +# one containing entries in abook format. * +# 2. it almost has more comments than code. * +# * +# This program is free software; you can redistribute it and/or modify * +# it under the terms of the GNU General Public License as published by * +# the Free Software Foundation; either version 2 of the License, or * +# (at your option) any later version. * +# * +# This program is distributed in the hope that it will be useful, * +# but WITHOUT ANY WARRANTY; without even the implied warranty of * +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# GNU General Public License for more details. * +# * +# You should have received a copy of the GNU General Public License * +# along with this program; if not, write to the Free Software * +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * +#==============================================================================* + +use strict; + +($#ARGV >= 1) or die + "usage: vcard2abook.pl \noutput file will be overwritten!\n"; + +my $vcards="$ARGV[0]"; +my $abook ="$ARGV[1]"; +my $key; + +my %conversions = ( + "FN" => "name=", + "NICKNAME" => "nick=", + "EMAIL" => "email=", + "ORG" => "notes=", + "NOTE" => "notes=", + "URL" => "url=", + + "TEL;HOME" => "phone=", + "TEL;PREF" => "phone=", + "TEL;VOICE" => "phone=", + "TEL;MSG" => "phone=", + "TEL;VIDEO" => "phone=", + "TEL;MODEM" => "phone=", + "TEL;ISDN" => "phone=", + "TEL;WORK" => "workphone=", + "TEL;CELL" => "mobile=", + "TEL;PAGER" => "mobile=", + "TEL;CAR" => "mobile=", + "TEL;FAX" => "fax=", + ); + +open (VCARDS,"$vcards") or quit("couldn't open $vcards"); +open (ABOOK,">$abook") or quit("couldn't open $abook for writing"); + +while () { + if (/^\s*$/) { } + elsif (/^BEGIN:VCARD/i) { print ABOOK "[]\n"; } + elsif (/^END:VCARD/i) { print ABOOK "\n"; } + else { + chomp; my @sections=split /:/, $_, 2; + if ($sections[0] =~ /^ADR/i) { + my @fields=split /;/, $sections[1]; + if ($fields[2]) {print ABOOK "address=$fields[2]\n";} + if ($fields[3]) {print ABOOK "city=$fields[3]\n"; } + if ($fields[4]) {print ABOOK "state=$fields[4]\n"; } + if ($fields[5]) {print ABOOK "zip=$fields[5]\n"; } + if ($fields[6]) {print ABOOK "country=$fields[6]\n";} + } + else { + foreach $key (keys %conversions) { + if ($sections[0] =~ /^$key/i) { + print ABOOK "$conversions{$key}$sections[1]\n"; + } + } + } + } +} + +close (VCARDS) or quit("couldn't close $vcards"); +close (ABOOK) or quit("couldn't close $abook"); + +sub quit { + print "whoops! $_[0]:\n $!\n"; die; +}