#!/usr/local/bin/perl -w # $Id: palm-ldif2csv,v 1.2 2000/09/06 10:38:27 mas Exp $ # palm.ldif2csv: Reads an ldif file and writes a comma-separated file that # contains most (but possibly not all) relevant information from the ldif file. # # Copyright 1999-2000 Marc Andr Selig. # # 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Fields in comma-separated vs. ldif files: # Last name sn # First name givenname # Title title # Company o [should really be o+", "+ou] # Work telephonenumber # Home homephone # Fax facsimiletelephonenumber # Other cellphone # E-mail mail # Address streetaddress # City locality # State st # Zip Code postalcode # Country countryname # Custom 1 "" # Custom 2 "" # Custom 3 "" # Custom 4 "" # Notiz description # see ldif2comma for further details and updates use strict; use MIME::Base64; my @fields = ("sn", "givenname", "title", "o", "telephonenumber", "homephone", "facsimiletelephonenumber", "cellphone", "mail", "streetaddress", "locality", "st", "postalcode", "countryname", "cust1", "cust2", "cust3", "cust4", "description"); $/ = ""; # enable paragraph mode while (<>) { my %thisrecord = (); foreach my $field (@fields) { $thisrecord{$field} = ""; } s/\n^ //msg; # if newline is followed by space, remove both while (m/^([^:]*:?): (.*)/mg) { my ($field, $data) = ($1, $2); if ($field =~ s/:$//) { $data = decode_base64($data); } # Remove quotes from data fields # pilot-addresses does not know how to handle them $data =~ s/\"/\'/g; # simple conversion UTF-8 to latin1 # (replace by tr///UC or similar for perl 5.6) $data =~ s/ä//g; $data =~ s/ö//g; $data =~ s/ü//g; $data =~ s/Ä//g; $data =~ s/Ö//g; $data =~ s/Ü//g; $data =~ s/ß//g; $data =~ s/á//g; $data =~ s/à//g; $data =~ s/â//g; $data =~ s/é//g; $data =~ s/è//g; $data =~ s/ê//g; $data =~ s/í//g; $data =~ s/ì//g; $data =~ s/î//g; $data =~ s/ó//g; $data =~ s/ò//g; $data =~ s/ô//g; $data =~ s/ú//g; $data =~ s/ù//g; $data =~ s/û//g; $data =~ s/ç//g; $data =~ s/Ç//g; $data =~ s/Á//g; $data =~ s/À//g; $data =~ s/Â//g; $data =~ s/É//g; $data =~ s/È//g; $data =~ s/Ê//g; $data =~ s/Í//g; $data =~ s/Ì//g; $data =~ s/Î//g; $data =~ s/Ó//g; $data =~ s/Ò//g; $data =~ s/Ô//g; $data =~ s/Ú//g; $data =~ s/Ù//g; $data =~ s/Û//g; $thisrecord{$field} = $data; } foreach my $field (@fields) { # %thisrecord is fully initialized, never undefined print '"', $thisrecord{$field}, '",'; } print '""', "\n"; }