#!/usr/local/bin/perl # psiontobbdb: Converts Psion vcard format from Contacts # application to BBDB format # Copyright (C) 2000 Ramin Nakisa # 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. require "getopts.pl"; &Getopts('h'); if (defined($opt_h)) { print <) { s/\cM//g; if (/^N;/) # Name { chomp; s/^N;//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELLABEL\d+\=//g; @fieldnames = split( /\;/, $_[0] ); @fieldvalues = split( /\;/, $_[1] ); for ( $i = 0; $i <= $#fieldnames; $i++ ) { # print $fieldnames[$i], " ", $fieldvalues[$i], "\n"; $data{$id,$fieldnames[$i]} = $fieldvalues[$i]; } # print "Field names: ", join( ",", @fieldnames ), "\n"; # print "Field values: ", join( ",", @fieldvalues ), "\n"; } if (/^ADR;/) { chomp; s/^ADR;(WORK|HOME);//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELLABEL\d+\=//g; @fieldnames = split( /\;/, $_[0] ); @fieldvalues = split( /\;/, $_[1] ); for ( $i = 0; $i <= $#fieldnames; $i++ ) { # print $fieldnames[$i], " ", $fieldvalues[$i], "\n"; # if ( $fieldnames[$i] eq " $data{$id,$fieldnames[$i]} = $fieldvalues[$i]; } # print "Field names: ", join( ",", @fieldnames ), "\n"; # print "Field values: ", join( ",", @fieldvalues ), "\n"; } if (/^EMAIL;INTERNET;/) { chomp; s/^EMAIL;INTERNET;(WORK|HOME);//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELFIELDLABEL\=//g; $fieldname = $_[0]; $fieldvalue = $_[1]; $data{$id,$fieldname} = $fieldvalue; # print "Field name: ", $fieldname, "\n"; # print "Field value: ", $fieldvalue, "\n"; } if (/^TEL;/) { chomp; s/^TEL;(WORK|HOME);(CELL|FAX){0,1};{0,1}//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELFIELDLABEL\=//g; $fieldname = $_[0]; $fieldvalue = $_[1]; $data{$id,$fieldname} = $fieldvalue; # print "Field name: ", $fieldname, "\n"; # print "Field value: ", $fieldvalue, "\n"; } if (/^ORG;/) { chomp; s/^ORG;//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELFIELDLABEL\=//g; $fieldname = $_[0]; ( $fieldvalue = $_[1] ) =~ s/;//; $data{$id,$fieldname} = $fieldvalue; # print "Field name: ", $fieldname, "\n"; # print "Field value: ", $fieldvalue, "\n"; } if ( /^NOTE;/ ) { $NotesStarted = 1; chomp; s/^NOTE;//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELFIELDLABEL\=//g; ( $fieldname = $_[0] ) =~ s/;ENCODING=QUOTED-PRINTABLE//; $fieldvalue = $_[1]; # $data{$id,$fieldname} = $fieldvalue; # print "Field name: ", $fieldname, "\n"; # print "Field value: ", $fieldvalue, "\n"; } if ( $NotesStarted ) { chomp; $l = $_; $l =~ s/X-EPOCCNTMODELFIELDLABEL=Notes(;ENCODING=QUOTED-PRINTABLE){0,1}://; $l =~ s/={0,1}$//g; # remove continuation symbol = $data{$id,$fieldname} .= $l; $data{$id,$fieldname} =~ s/=0D=0A/\n /g; # translate CR symbol # print $l; if ( $_ !~ /=$/ ) { $NotesStarted = 0; } } # if ( /END:VCARD/ ) # { # print "Name: "; # if ( defined( $data{$id,"Title"} ) ) # { # print $data{$id,"Title"}, " "; # } # if ( defined( $data{$id,"First name"} ) ) # { # print $data{$id,"First name"}, " "; # } # if ( defined( $data{$id,"Middle name"} ) ) # { # print $data{$id,"Middle name"}, " "; # } # if ( defined( $data{$id,"Last name"} ) ) # { # print $data{$id,"Last name"}, " "; # } # if ( defined( $data{$id,"Suffix"} ) ) # { # print $data{$id,"Suffix"}, " "; # } # print "\n"; # if ( defined( $data{$id,"Company"} ) ) # { # print " Company : ", $data{$id,"Company"}, "\n"; # } # if ( defined( $data{$id,"Work email"} ) ) # { # print " Work email : ", $data{$id,"Work email"}, "\n"; # } # if ( defined( $data{$id,"Home email"} ) ) # { # print " Home email : ", $data{$id,"Home email"}, "\n"; # } # if ( defined( $data{$id,"Work tel"} ) ) # { # print " Work tel : ", $data{$id,"Work tel"}, "\n"; # } # if ( defined( $data{$id,"Work fax"} ) ) # { # print " Work fax : ", $data{$id,"Work fax"}, "\n"; # } # if ( defined( $data{$id,"Home tel"} ) ) # { # print " Home tel : ", $data{$id,"Home tel"}, "\n"; # } # if ( defined( $data{$id,"Home fax"} ) ) # { # print " Home fax : ", $data{$id,"Home fax"}, "\n"; # } # if ( defined( $data{$id,"Mobile"} ) ) # { # print " Mobile : ", $data{$id,"Mobile"}, "\n"; # } # if ( defined( $data{$id,"Notes"} ) ) # { # print " Notes : ", $data{$id,"Notes"}, "\n"; # } # print "\n"; # $id++; # } if ( /END:VCARD/ ) { print "["; # " " print "\""; if ( defined( $data{$id,"First name"} ) ) { print $data{$id,"First name"}; } if ( defined( $data{$id,"First name"} ) && defined( $data{$id,"Middle name"} ) ) { print " "; } if ( defined( $data{$id,"Middle name"} ) ) { print $data{$id,"Middle name"}; } print "\""; # "" print " \""; if ( defined( $data{$id,"Last name"} ) ) { print $data{$id,"Last name"}; } # Not a person (no first or last name), so must be a company if ( ! defined( $data{$id,"Last name"} ) && ! defined( $data{$id,"Last name"} ) ) { print $data{$id,"Company"}; } print "\""; if ( defined( $data{$id,"Suffix"} ) ) { print $data{$id,"Suffix"}, " "; } print " nil nil "; if ( defined( $data{$id,"Work tel"} ) || defined( $data{$id,"Home tel"} ) ) { print "("; if ( defined( $data{$id,"Home tel"} ) ) { print "[\"home\" \"", $data{$id,"Home tel"}, "\"]"; } if ( defined( $data{$id,"Work tel"} ) && defined( $data{$id,"Home tel"} ) ) { print " "; } if ( defined( $data{$id,"Work tel"} ) ) { print "[\"work\" \"", $data{$id,"Work tel"}, "\"]"; } print ")"; } else { print " nil"; } print " nil "; if ( defined( $data{$id,"Work email"} ) || defined( $data{$id,"Home email"} ) ) { print "("; if ( defined( $data{$id,"Work email"} ) ) { print "\"", $data{$id,"Work email"}, "\""; } if ( defined( $data{$id,"Work email"} ) && defined( $data{$id,"Home email"} ) ) { print " "; } if ( defined( $data{$id,"Home email"} ) ) { print "\"", $data{$id,"Home email"}, "\""; } print ")"; } else { print " nil"; } print " ((creation-date . \"2000-03-28\") (timestamp . \"2000-03-28\")) nil"; print "]\n"; # if ( defined( $data{$id,"Company"} ) ) # { # print " Company : ", $data{$id,"Company"}, "\n"; # } # if ( defined( $data{$id,"Work email"} ) ) # { # print " Work email : ", $data{$id,"Work email"}, "\n"; # } # if ( defined( $data{$id,"Home email"} ) ) # { # print " Home email : ", $data{$id,"Home email"}, "\n"; # } # if ( defined( $data{$id,"Work tel"} ) ) # { # print " Work tel : ", $data{$id,"Work tel"}, "\n"; # } # if ( defined( $data{$id,"Work fax"} ) ) # { # print " Work fax : ", $data{$id,"Work fax"}, "\n"; # } # if ( defined( $data{$id,"Home tel"} ) ) # { # print " Home tel : ", $data{$id,"Home tel"}, "\n"; # } # if ( defined( $data{$id,"Home fax"} ) ) # { # print " Home fax : ", $data{$id,"Home fax"}, "\n"; # } # if ( defined( $data{$id,"Mobile"} ) ) # { # print " Mobile : ", $data{$id,"Mobile"}, "\n"; # } # if ( defined( $data{$id,"Notes"} ) ) # { # print " Notes : ", $data{$id,"Notes"}, "\n"; # } # print "\n"; $id++; } }