[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    ldif to csv / Netscape Address Book to KPilot
From:       Eric Nichols <enichols () uswest ! net>
Date:       1999-07-30 3:39:38
[Download RAW message or body]

I and am sure others have the need to be able to sync Netscape address
book with KPilot. I found the beginings of a perl script on the net. I
have modified the script a little but this is far beyond my current
knowledge of programming. I was hoping someone might enjoy tackling this
or have suggestions on an alternative method.

#!/usr/sbin/perl
###############################################
##           Version 11.20.97                ##
###############################################
##          address_convert.cgi              ##
###############################################
##  Converts Netscape .ldif to .addressbook  ##
##   (c)1997 Daevid Vincent                  ##
##   EMAIL: dvincent@TheMatrix.com           ##
##   WEB: http://TheMatrix.com/~dae51d       ##
## Unauthorized use of this code is strictly ##
## prohibited and subject to criminal        ##
## prosecution and or death                  ##
###############################################

#EN 07/26/1999 Modified by Eric Nichols for exporting in a comma
separated format readable by KPilot enichols@uswest.net

if ($#ARGV < 0) {print "\n\tUsage: $0 netscape.ldif.file >
kpilot.csv\n\n"; exit;}

open(NetscapeFILE,"<$ARGV[0]") || die("Can't open file $_[0]: $!");

        $x = $l = 0;
        while (<NetscapeFILE>) {

               chomp;

#EN 07/26/1999 I removed chop because it was striping givenname and sn
of their last charachter
# chop; # remove the newlines and ^M character, etc.

                if (/^dn: cn=(.*),mail=(.*)/i)  { $x++; $NAME[$x] = $1;
$EMAIL[$x] = $2;}
                if (/^mail: (.*)/i)  { $P5[$x] = $1;}
                if (/^givenname: (.*)/i)  { $FN[$x] = $1}
                if (/^sn: (.*)/i)  { $LN[$x] = $1;}
                if (/^homephone: (.*)/i)  { $P1[$x] = $1}
                if (/^o: (.*)/i)  { $CO[$x] = $1;}
                if (/^locality: (.*)/i)  { $CI[$x] = $1;}
                if (/^st: (.*)/i)  { $ST[$x] = $1;}
                if (/^description: (.*)/i)  { $C3[$x] = $1;}
                if (/^title: (.*)/i)  { $TI[$x] = $1;}
                if (/^streetaddress: (.*)/i)  { $AD[$x] = $1;}
                if (/^postalcode: (.*)/i)  { $ZI[$x] = $1;}
                if (/^countryname: (.*)/i)  { $CT[$x] = $1;}
                if (/^telephonenumber: (.*)/i)  { $P2[$x] = $1;}
                if (/^facsimiletelephonenumber: (.*)/i)  { $P3[$x] =
$1;}
                if (/^cellphone: (.*)/i)  { $P4[$x] = $1}
                if (/^ou: (.*)/i)  { $C1[$x] = $1;}
                if (/^pagerphone: (.*)/i)  { $C4[$x] = $1}
                if (/^homeurl: (.*)/i)  { $C2[$x] = $1;}

                # special LIST handling
#               if (/^dn: cn=(.*)[^,=]/i)
#                   {   $LISTNAME[$l] = $1;
#                       $lm = 0; # start a new tally of members
#                        while (/^\S/) {
#                               if (/member: cn=(.*),mail=(.*)/) {
$LISTMEMBER[$lm] = $2; $lm++; }
#                               if (/^description: (.*)/i)  {
$LISTDESC[$l] = $1; }
#                               if (/^xmozillanickname: (.*)/i)  {
$LISTNICK[$l] = $1; }
#                        } # while list
#                       $l++;
#                   } # if list

        } # main while loop

close(NetscapeFILE);

        $x = 0;
        while ($x <= $#NAME)  { print
"$LN[$x]\,$FN[$x]\,$CO[$x]\,$P1[$x]$P2[$x]\,$P3[$x]\,$P4[$x]\,$P5[$x]\,AD[$x]\,$CI[$x]\,$ST[$x]\,$ZI[$x]$CT[$x]\,$TI[$x]\,$C1[$x]\,$C2[$x]\,C3[$x]\,$C4[$x]\n";
 $x++; }


-- 
Eric Nichols	Corvallis, Oregon 97330
CounselTech	819 NW 31st Street
(541) 990-7996	http://www.alephent.com/counseltech/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic