Import Squirrel mail addresses into Evolution contacts PDF Print E-mail
Written by Carl Friis-Hansen   
Tuesday, 10 November 2009 13:02

 

I have modified Héctor M. Monacci's perl script from 2005 to match the fields in Squirrel mail addresses.

Export the addresses from Squirrel mail as a csv file and run this perl program like this:

./csv2vcf myaddresses.csv myaddresses.vcf

Here is the program:


#!/usr/bin/perl

#############################################################################
# csv2vcf takes an address book csv file as exported by Squirrel mail
# and turns it into a VCF file to be imported as Evolution contacts
# v0.0.2.sq
#
# Copyright (c) 2005 Héctor M. Monacci
# Contact This e-mail address is being protected from spambots. You need JavaScript enabled to view it
#
# Prompts anglicised 2008 by Tony Whelan
#
# Modified to import Squirrel mail addreeses by Carl Friis-Hansen (cjfh)
# 20091110
#############################################################################

use strict;
#use warnings;
#use diagnostics;
use locale;
use Encode;
my $contenido_total;
my @renglones;
my $in = $ARGV[0];
my $out = $ARGV[1];
sub usage
{

print STDERR << "--EndOfUsage";
Reads an address book file exported from Thunderbird in tab-separated format
and creates a new file in VCF format for importing to Evolution address book.

Virtually any input and output file names are permitted.
The input file must exist and the script will abort if not found.

Why the need? Because Evolution's built-in import utility does not read
LDIF/CSV/TXT files correctly; it omits/misfiles some data.

Script written 2005 by Héctor M. Monacci
This prompt screen anglicised and expanded 2008 by Tony Whelan

Use: $0 input-file output-file
--EndOfUsage
exit;

}

usage() unless(defined($in) && defined($out));

local( $/, *INFILE ) ;
open (INFILE, $in)
or die "Unable to open $in: $!\n";

$contenido_total = ;
close(INFILE);

#

# Eliminamos comillas:
$contenido_total =~ s/"//g;
#
# Cargamos en un array:
#
@renglones = split(/\n/, $contenido_total);
#
# Asignamos a los campos:
#
# cjfh: Changed split(/\t/, $_) to split(/,/, $_)
# in order to use csv insteat of tsv
#
my $este;
my @resultado;
# Fields below are modified so that the 6 fields from
# the Squirrel mail adresses fit.
foreach (@renglones) {
my @rengloncitos = split(/,/, $_);
my $_00_First_Name = $rengloncitos[ 2];
my $_01_Last_Name = $rengloncitos[ 3];
my $_02_Screen_Name = $rengloncitos[ 1];
my $_03_Nickname = $rengloncitos[ 0];
my $_04_Email_Address = $rengloncitos[ 4];
my $_05_Email_2_Address = $rengloncitos[ 6];
my $_06_Business_Phone = $rengloncitos[ 7];
my $_07_Home_Phone = $rengloncitos[ 8];
my $_08_Business_Fax = $rengloncitos[ 9];
my $_09_Pager = $rengloncitos[10];
my $_10_Mobile_Phone = $rengloncitos[11];
my $_11_Home_Street = $rengloncitos[12];
my $_12_Home_Street_2 = $rengloncitos[13];
my $_13_Home_City = $rengloncitos[14];
my $_14_Home_State = $rengloncitos[15];
my $_15_Home_Postal_Code = $rengloncitos[16];
my $_16_Home_Country = $rengloncitos[17];
my $_17_Business_Street = $rengloncitos[18];
my $_18_Business_Street_2 = $rengloncitos[19];
my $_19_Business_City = $rengloncitos[20];
my $_20_Business_State = $rengloncitos[21];
my $_21_Business_Postal_Code = $rengloncitos[22];
my $_22_Business_Country = $rengloncitos[23];
my $_23_Title = $rengloncitos[24];
my $_24_Department = $rengloncitos[25];
my $_25_Organization = $rengloncitos[26];
my $_26_Business_Web = $rengloncitos[27];
my $_27_Web_Page = $rengloncitos[28];
my $_28_s = $rengloncitos[29];
my $_29_t = $rengloncitos[30];
my $_30_u = $rengloncitos[31];
my $_31_v = $rengloncitos[32];
my $_32_w = $rengloncitos[33];
my $_33_x = $rengloncitos[34];
my $_34_y = $rengloncitos[35];
my $_35_Notes = $rengloncitos[5];
my $_36_z = $rengloncitos[36];

my $plantilla = "BEGIN:VCARD
VERSION:3.0
URL:$_27_Web_Page
TITLE:$_23_Title
ORG:$_25_Organization;$_24_Department;
NICKNAME:$_03_Nickname
NOTE:$_35_Notes
FN:$_00_First_Name $_01_Last_Name
# Temp MOD to pull the full name from nickname
# instead of fullname field
# Replace FN line above with the line below
# FN:$_03_Nickname
# end temp MOD Tony W.
N:$_01_Last_Name;$_00_First_Name;;;
X-EVOLUTION-FILE-AS:$_01_Last_Name, $_00_First_Name
X-MOZILLA-HTML:TRUE
EMAIL;TYPE=HOME:$_04_Email_Address
EMAIL;TYPE=WORK:$_05_Email_2_Address
TEL;TYPE=WORK;TYPE=VOICE:$_06_Business_Phone
TEL;TYPE=HOME;TYPE=VOICE:$_07_Home_Phone
TEL;TYPE=CELL:$_10_Mobile_Phone
TEL;TYPE=WORK;TYPE=FAX:$_08_Business_Fax
TEL;TYPE=PAGER:$_09_Pager
ADR;TYPE=WORK:;;$_17_Business_Street $_18_Business_Street_2;$_19_Business_City;$_20_Business_State;$_21_Business_Postal_Code;$_22_Business_Country

LABEL;TYPE=WORK:$_17_Business_Street $_18_Business_Street_2\\n$_21_Business_Postal_Code $_19_Business_City, $_20_Business_State\\n$_22_Business_Country

ADR;TYPE=HOME:;;$_11_Home_Street $_12_Home_Street_2;$_13_Home_City;$_14_Home_State;$_15_Home_Postal_Code;$_16_Home_Country

LABEL;TYPE=HOME:$_11_Home_Street $_12_Home_Street_2\\n$_15_Home_Postal_Code $_13_Home_City, $_14_Home_State\\n$_16_Home_Country

END:VCARD

";

#
# Correcciones particulares:
#
$plantilla =~ s/,/\\,/g;

$plantilla =~ s/\\,\s$//g;
$plantilla =~ s/: \\n \\, \\n/:/g;
$plantilla =~ s/\\, \\n/\\n/g;
$plantilla =~ s/\\, \n/\n/g;
$plantilla =~ s/:;; ;;;;/:/g;
$plantilla =~ s/.*\:\n//g;
push (@resultado, $plantilla);

}

# Imprimimos el resultado en un archivo VCF:
open (OUTFILE, ">$out")
or die "Unable to create $out: $!\n";
print OUTFILE @resultado;
close(OUTFILE);


 

Attachments:
Download this file (csv2vcf.tar.gz)csv2vcf.tar.gz[Convert Squirrel mail address csv file into Evolution vcf file for import into Evolution]2 Kb10/11/09 13:12
 

Add comment

To be able to vote and have easier access to write comments, etc., go to Login and register yourself.
Your user name and email will never leave this website.


Security code
Refresh