Fwd: Re: [turba] Importing old Imp contact to Turba

Jan Schneider jan at horde.org
Tue Apr 15 15:14:28 PDT 2003



----- Weitergeleitete Nachricht von schimkat at hum.auc.dk -----
    Datum: Tue, 15 Apr 2003 14:06:27 +0200
    Von: Søren Schimkat <schimkat at hum.auc.dk>
Antwort an: Søren Schimkat <schimkat at hum.auc.dk>
 Betreff: Re: [turba] Importing old Imp contact to Turba
      An: Jan Schneider <jan at horde.org>

Thanks.

The script didn't work with Postgres.. so i've altered it a bit. I've
attatched the altered script if you want a copy.

Regards Søren



Jan Schneider wrote:

>Quoting Søren Schimkat <schimkat at hum.auc.dk>:
>
>
>
>>Hi Guys
>>
>>Does anyone have a script for easily importing the old Imp 2.x adresses
>>to Turba 1.1?
>>
>>
>
>imp/scripts/imp2turba.pl
>
>Jan.
>
>--
>http://www.horde.org - The Horde Project
>http://www.ammma.de - discover your knowledge
>http://www.tip4all.de - Deine private Tippgemeinschaft
>
>
>



----- Ende der weitergeleiteten Nachricht -----


Jan.

--
http://www.horde.org - The Horde Project
http://www.ammma.de - discover your knowledge
http://www.tip4all.de - Deine private Tippgemeinschaft
-------------- next part --------------
#!/usr/bin/perl
#
#    $Horde: imp/scripts/imp2turba.pl,v 1.2.2.4 2002/05/26 23:06:56 jan Exp $
#
#    File:      imp2turba.pl
#    Author:    Micah Anderson - micah at riseup.net
#    Version:   1.1
#
#    Date:      8/7/01
#    Purpose:   This script converts an old imp addressbook database contents
#               to the newer turba addressbook format.
#
#    Usage:     Modify the variables at the beginning of the script
#               so that your database tpye/user/password, location and imp
#               database and turba database are correct. Then simply run
#               ./imp2turba.pl, if you have made the script executable, or
#               perl ./imp2turba.pl
#
#    Date:	    5/12/01
#               tuning for imp2.2.7 to turba 1.0 by Christophe Guilloux <rootix at bootix.net>
#
#    Date:      27/5/02
#               make the database type configurable.


use DBI;


my $IMP_DATABASE_LOCATION   = 'hostname';
my $IMP_DATABASE_PORT       = '5432';
my $IMP_DATABASE_USER       = 'username';
my $IMP_DATABASE_PASS       = '********';
my $IMP_DATABASE_TYPE       = 'Pg';
my $IMP_DATABASE            = 'dbname';
my $IMP_TABLE               = 'imp_addr';

my $TURBA_DATABASE_LOCATION = 'hostname';
my $TURBA_DATABASE_PORT     = '5432';
my $TURBA_DATABASE_USER     = 'username';
my $TURBA_DATABASE_PASS     = '********';
my $TURBA_DATABASE_TYPE     = 'Pg';
my $TURBA_DATABASE          = 'dbname';
my $TURBA_TABLE             = 'turba_objects';


my $dbi_options = {RaiseError => 1, ChopBlanks => 1, AutoCommit => 1};

$db_imphandle = DBI->connect("DBI:$IMP_DATABASE_TYPE:dbname=$IMP_DATABASE;host=$IMP_DATABASE_LOCATION;port=$IMP_DATABASE_PORT",
                             $IMP_DATABASE_USER, $IMP_DATABASE_PASS, $dbi_options)
                || die ("Connection error: $DBI::errstr");

$db_turbahandle = DBI->connect("DBI:$TURBA_DATABASE_TYPE:dbname=$TURBA_DATABASE;host=$TURBA_DATABASE_LOCATION;port=$TURBA_DATABASE_PORT",
                               $TURBA_DATABASE_USER, $TURBA_DATABASE_PASS, $dbi_options)
                  || die ("Connection error: $DBI::errstr");

$imp_statement = $db_imphandle->prepare("SELECT * FROM $IMP_TABLE");
$imp_statement->execute();

while (my ($owner, $address, $nickname, $fullname) = $imp_statement->fetchrow_array()) {

    @chars      = ("A" .. "Z", "a" .. "z", 0 .. 9, qw(! @ $ % ^ & *));
    $unique_key = join("", @chars[ map {rand @chars} (1 .. 31) ]);

    # Quote the strings appropriately for the database
    my $quoted_key      = $db_imphandle->quote($unique_key);
    my $quoted_owner    = $db_imphandle->quote($owner);
    my $quoted_fullname = $db_imphandle->quote($fullname);
    my $quoted_address  = $db_imphandle->quote($address);
    my $quoted_nickname = $db_imphandle->quote($nickname);

    $turba_statement = "INSERT INTO $TURBA_TABLE VALUES
                        ($quoted_key, $quoted_owner, $quoted_fullname,
                        $quoted_nickname,$quoted_address, '','','','','','','','','')";

    $turba_statement = $db_turbahandle->prepare($turba_statement) || die "prepare: $$stmt: $DBI::errstr";
    $turba_statement->execute || die "execute: $$stmt: $DBI::errstr";
    $turba_statement->finish();

}

$imp_statement->finish();
$db_imphandle->disconnect;
$db_turbahandle->disconnect;


More information about the turba mailing list