#!/usr/bin/perl -w # This script convert Atmail Address Book to RoundCube Vcard format # # In Atmail CSV file you will find the first line with name data fields # the script will just fetch 3 fields (email, name, surname) required by # Roundcube addressbook. # use strict; # set the points my $email=3; my $name=8; my $surname=19; # END set the points my $i=0; sub makev($$$) { my $email=shift; my $name=shift; my $surname=shift; print W ("BEGIN:VCARD\nVERSION:3.0\nFN:$name\nN:$surname;$name;;;\nEMAIL;type=INTERNET;type=HOME;type=pref:$email\nEND:VCARD\n"); } if(!$ARGV[0]) { die("Please use\n\tcsv2vcard.pl\t"); } my $outputz=$ARGV[0]; $outputz=~ s/\.csv$/\.vcard/; if(!$outputz) { die("Error while generated vcard output file"); } # Open the csv file open(A,$ARGV[0]) || die; # Open output file to write on open(W,">".$outputz)||die; while() { if($_ =~ m/".*",/) { next; } my @jok=split(/,/,$_); my $jok; if($jok[$email] =~ /\@/) { } else { die("Check ($jok[$email]): is it an email address ?"); } if(!$jok[$name]) { my @emas=split(/\@/,$jok[$email]); my $emas; $jok[$name]=$emas[0]; } if($jok[$email] && $jok[$name]) { #print($jok[3]."\n"); makev($jok[3],$jok[$name],$jok[19]); $i++; } else { chomp($_); die("NO data on ..($_).."); } } close(A); # close output close(W); print("Converted $i contacts\n"); #EOF