Import Contacts to Kerio Webmail


2012/03/25

Importing contacts for use in Kerio Webmail is not difficult. Here are two ways to do that.


Kerio Webmail Contacts

There are easy ways to get contacts onto your Kerio Connect mail server so that they are available from Kerio Webmail. For example, I have a Gmail account and have accumulated hundreds of contacts over the years. I'd like to have those available to me when I use Kerio Webmail.


Export from Gmail

This happens to be very easy, but most other mail programs have something similar. You'll have a choice of export formats, and what you choose depends upon your next step. If you have Outlook with the free Kerio Outlook connector installed, choose a "csv" file.

Export Gmail Contacts

If you don't have Outlook, choose Vcard. I'll show you a Perl script that will read that file and create what Kerio needs to see.

With Outlook

Find "Import" (where it is varies with Outlook versions) and choose "Import from another program or file" and then choose "Comma Separated Values (Windows)".

Import Contacts

Select your exported file and then choose the destination on the Kerio server:

That needs to be a "contacts" folder that already exists.

Select destination

Yes, it's really that easy - if you have Outlook.

Without Outlook

If you don't have Outlook, I'll give you a Perl script that can create the contact files ready to put on the server.

A couple of caveats:

I tested this on Kerio Connect 7.3.2 build 6388. The method described here may not be suitable for earlier or later versions. I tested this on Ubuntu Linux; the Perl script should work on Windows (you'll need to install Perl, though) but you are responsible for your own testing and usage.

What this script does is read a Google exported vcf file and convert it to Kerio contacts. I STRONGLY suggest creating a test user to play with until you fully understand how the script works.

If you are one of my current customers, of course I will assist you with anything you need.

The script

#!/usr/bin/perl
$input="contacts.vcf";
# whatever you called your exported file
$outputdir="contacts.out";
mkdir($outputdir);
# Temporary storage for the Kerio .eml files
# 
$x=9; 
# Starting contact number - one more than number 
# of contacts you currently have in your Kerio Webmail account
# Read the file
open(I,$input);
writefile();

while (<I>) {
 chomp;
 print "creating contact $x \n";
 if (/^END:VCARD/) {
   print O "$_\n";
   close O;
   $x++;
   writefile() if not eof(I);
   next;
   }
print O "$_\n";
}

sub writefile {
   $ofile=sprintf "%0.8x.eml\n",$x;
   open(O,">$outputdir/$ofile");
   print O <<EOF;
Subject: 
Date: Sun, 25 Mar 2012 11:29:38 -0400
Content-Type: text/vcard; charset="utf-8"
Content-Transfer-Encoding: 8bit

EOF
}
 

This script puts the .eml files (Kerio contacts) in a temporary directory. When you are ready, you are going to move them into place and ask the server to reindex your files.

I did this with the server running, but if you want to be ultra cautious, shut the server down before copying or moving the files.

Where do they go? In my case (running Linux):

cp  *.eml  /opt/kerio/mailserver/store/mail/aplawrence.com/tony/Contacts/?msgs/
 

I then told the server to reindex my files:

Reindex

That's it. The contacts are now available for use in Webmail (or will be when the reindexing completes, which was a matter of seconds for me)..

Here's a bonus: Gmail adds Vcard data that Kerio Webmail does not. Some of that will be visible in your contacts - even if you later edit the contact in Webmail.

Already have the contacts but not in Vcard?

Whatever the format of the contacts is, a simple script can convert them. Again, if you are a current customer of mine, I'm happy to help you with whatever you need.

Here's a version that reads from CSV:

#!/usr/bin/perl
$input="contacts.csv";
# whatever you called your exported file
$outputdir="contacts/tony";
mkdir($outputdir);
# Temporary storage for the Kerio .eml files
# 
$x=2; 
# Starting contact number - one more than number 
# of contacts you currently have in your Kerio Webmail account
# Read the file
open(I,$input);

while (<I>) {
 next if /^#/;
 chomp;
 print "creating contact $x \n";
# First Name
# 1 Last Name,
# 2 Name
# 3 ,Nickname
# 4 ,E-mail Address
# 5 ,Home Street
# 6 ,Home City
# 7 ,Home Postal Code
# 8 ,Home State
# 09 ,Home Country/Region
# 10 ,Home Phone
# 11 ,Business Phone
# 12,Company
# 13 ,Job Title
 @new=();
 split_string($_);
# modify to match your csv, of course
 $N=$new[2];
 $FN="$[0] $new[1]";
 $ORG=$new[12];
 $TITLE=$new[13];
 $TELWORK=$new[11];
 $TELHOME=$new[10];
 $EMAIL=$new[4];
   writefile();
}
# N:Gump;Forrest
# FN:Forrest Gump
# ORG:Bubba Gump Shrimp Co.
# TITLE:Shrimp Man
# PHOTO;VALUE=URL;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif
# TEL;TYPE=WORK,VOICE:(111) 555-1212
# TEL;TYPE=HOME,VOICE:(404) 555-1212
# ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
# LABEL;TYPE=WORK:100 Waters Edge\nBaytown, LA 30314\nUnited States of America
# ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
# LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited States of America
# EMAIL;TYPE=PREF,INTERNET:[email protected]

sub writefile {
   $ofile=sprintf "%0.8x.eml\n",$x++;
   open(O,">$outputdir/$ofile");
   print "$outputdir/$ofile \n";
   print O  <<EOF;
Subject: 
Date: Sun, 25 Mar 2012 11:29:38 -0400
Content-Type: text/vcard; charset="utf-8"
Content-Transfer-Encoding: 8bit

BEGIN:VCARD
VERSION:3.0
PRODID:-//kerio.com/Contacts//NONSGML v1.0//EN
N:$N
FN:$FN
ORG:$ORG
TITLE:$TITLE
TEL;TYPE=WORK,VOICE:$TELWORK
TEL;TYPE=HOME,VOICE:$TELHOME
ADR;TYPE=WORK:;;$ADR_WORK
ADR;TYPE=HOME:;;$ADR_HOME
EMAIL;TYPE=PREF,INTERNET:$EMAIL
END:VCARD
EOF
}



sub split_string {
    my $text = shift;
    push(@new, $+) while $text =~ m{ \s*(
        # groups the phrase inside double quotes
        "([^\"\\]*(?:\\.[^\"\\]*)*)"\s*,?
        # groups the phrase inside single quotes
        | '([^\'\\]*(?:\\.[^\'\\]*)*)'\s*,?
        # trims leading/trailing space from phrase
        | ([^,\s]+(?:\s+[^,\s]+)*)\s*,?
        # just to grab empty phrases
        | (),
        )\s*}gx;
    push(@new, undef) if $text =~ m/,\s*$/;

}
 


Got something to add? Send me email.





(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Import Contacts to Kerio Webmail




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Anthony Lawrence



Kerio Connect Mailserver

Kerio Samepage

Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





If you ask "Should we be in space?" you ask a nonsense question. We are in space. We will be in space. (Frank Herbert)

I'm sure the universe is full of intelligent life. It's just been too intelligent to come here. (Arthur C. Clarke)








This post tagged: