#!/usr/local/bin/perl # psiontognomecard: Converts Psion vcard format from Epoc # Contacts application to GnomeCard vcard 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++ ) { $data{$id,$fieldnames[$i]} = $fieldvalues[$i]; } } if (/^ADR;/) { chomp; s/^ADR;(WORK|HOME);//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELLABEL\d+\=//g; $_[1] =~ s/=0D=0A/, /g; # translate CR symbol @fieldnames = split( /\;/, $_[0] ); @fieldvalues = split( /\;/, $_[1] ); for ( $i = 0; $i <= $#fieldnames; $i++ ) { $data{$id,$fieldnames[$i]} = $fieldvalues[$i]; } } if (/^EMAIL;INTERNET;/) { chomp; s/^EMAIL;INTERNET;(WORK|HOME);//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELFIELDLABEL\=//g; $fieldname = $_[0]; $fieldvalue = $_[1]; $data{$id,$fieldname} = $fieldvalue; } 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; } if (/^ORG;/) { chomp; s/^ORG;//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELFIELDLABEL\=//g; $fieldname = $_[0]; ( $fieldvalue = join("",@_[1..$#_]) ) =~ s/;//; $data{$id,$fieldname} = $fieldvalue; } if (/^URL;/) { chomp; s/^URL;//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELFIELDLABEL\=//g; $fieldname = $_[0]; ( $fieldvalue = join("",@_[1..$#_]) ) =~ s/;//; $data{$id,$fieldname} = $fieldvalue; } if ( /^NOTE;/ ) { $NotesStarted = 1; s/^NOTE;//; split(/\:/); $_[0] =~ s/X-EPOCCNTMODELFIELDLABEL\=//g; ( $fieldname = $_[0] ) =~ s/;ENCODING=QUOTED-PRINTABLE//; $fieldvalue = $_[1]; } if ( $NotesStarted ) { $l = $_; $l =~ s/X-EPOCCNTMODELFIELDLABEL=Notes(;ENCODING=QUOTED-PRINTABLE){0,1}://; $data{$id,$fieldname} .= $l; $data{$id,$fieldname} =~ s/=0D=0A/=0A/g; # translate CR symbol if ( $_ !~ /=$/ ) { $NotesStarted = 0; } } if ( /END:VCARD/ ) { print "BEGIN:VCARD\n"; # First field is FN, which is the record name # Not a person (no first or last name), so must be a company if ( ! defined( $data{$id,"First name"} ) && ! defined( $data{$id,"Last name"} ) ) { print "FN:"; print $data{$id,"Company"}; print "\n"; } else { print "FN:"; if ( defined( $data{$id,"First name"} ) ) { print $data{$id,"First name"}; if ( defined( $data{$id,"Middle name"} ) || defined( $data{$id,"Last name"} ) ) { print " "; } } if ( defined( $data{$id,"Middle name"} ) ) { print $data{$id,"Middle name"}; if ( defined( $data{$id,"Last name"} ) ) { print " "; } } if ( defined( $data{$id,"Last name"} ) ) { print $data{$id,"Last name"}; } print "\n"; } # N if ( defined( $data{$id,"Last name"} ) || defined( $data{$id,"Middle name"} ) || defined( $data{$id,"First name"} ) ) { print "N:"; if ( defined( $data{$id,"Last name"} ) ) { print $data{$id,"Last name"}; } print ";"; if ( defined( $data{$id,"First name"} ) ) { print $data{$id,"First name"}; } print ";"; if ( defined( $data{$id,"Middle name"} ) ) { print $data{$id,"Middle name"}; } print ";"; if ( defined( $data{$id,"Suffix"} ) ) { print $data{$id,"Title"}; } print ";"; if ( defined( $data{$id,"Suffix"} ) ) { print $data{$id,"Suffix"}; } print "\n"; } # ADR (Work) if ( defined( $data{$id,"Work address"} ) ) { print "ADR;WORK:"; if ( defined( $data{$id,"Work PO box"} ) ) { print $data{$id,"Work PO box"}; } print ";"; if ( defined( $data{$id,"Work ext address"} ) ) { print $data{$id,"Work ext address"}; } print ";"; if ( defined( $data{$id,"Work address"} ) ) { print $data{$id,"Work address"}; } print ";"; if ( defined( $data{$id,"Work city"} ) ) { print $data{$id,"Work city"}; } print ";"; if ( defined( $data{$id,"Work region"} ) ) { print $data{$id,"Work region"}; } print ";"; if ( defined( $data{$id,"Work p'code"} ) ) { print $data{$id,"Work p'code"}; } print ";"; if ( defined( $data{$id,"Work country"} ) ) { print $data{$id,"Work country"}; } print "\n"; } # ADR (Home) if ( defined( $data{$id,"Home address"} ) ) { print "ADR;HOME:"; if ( defined( $data{$id,"Home PO box"} ) ) { print $data{$id,"Home PO box"}; } print ";"; if ( defined( $data{$id,"Home ext address"} ) ) { print $data{$id,"Home ext address"}; } print ";"; if ( defined( $data{$id,"Home address"} ) ) { print $data{$id,"Home address"}; } print ";"; if ( defined( $data{$id,"Home city"} ) ) { print $data{$id,"Home city"}; } print ";"; if ( defined( $data{$id,"Home region"} ) ) { print $data{$id,"Home region"}; } print ";"; if ( defined( $data{$id,"Home p'code"} ) ) { print $data{$id,"Home p'code"}; } print ";"; if ( defined( $data{$id,"Home country"} ) ) { print $data{$id,"Home country"}; } print "\n"; } # TEL if ( defined( $data{$id,"Work tel"} ) || defined( $data{$id,"Home tel"} ) ) { if ( defined( $data{$id,"Home tel"} ) ) { print "TEL;HOME:", $data{$id,"Home tel"}, "\n"; } if ( defined( $data{$id,"Work tel"} ) ) { print "TEL;WORK:", $data{$id,"Work tel"}, "\n"; } if ( defined( $data{$id,"Mobile"} ) ) { print "TEL;CELL:", $data{$id,"Mobile"}, "\n"; } } # EMAIL if ( defined( $data{$id,"Work email"} ) || defined( $data{$id,"Home email"} ) ) { if ( defined( $data{$id,"Work email"} ) ) { print "EMAIL;INTERNET:", $data{$id,"Work email"}, "\n"; } if ( defined( $data{$id,"Home email"} ) ) { print "EMAIL;INTERNET:", $data{$id,"Home email"}, "\n"; } } # URL if ( defined( $data{$id,"Web page"} ) ) { print "URL:", $data{$id,"Web page"}, "\n"; } # NOTE if ( defined( $data{$id,"Notes"} ) ) { print "NOTE;QUOTED-PRINTABLE:", $data{$id,"Notes"}; } print "END:VCARD\n\n"; $id++; } }