Kerio Contacts Export Script (.eml to .vcf)

The Kerio Mailserver is a very good product in my eyes. It is easy to administer and offer almost all features needed in a groupware solution: Calendars, email, contacts, shared folders etc. It runs on Mac OS X, Linux and Windows and can operate as an Exchange replacement. It talks to all popular commercial and Open Source Clients such as AppleMail, Thunderbird, Outlook etc.

KMS stores contacts in the public folder as email messages. The body of the message is a V. 3.0 VCard. The following script exports all contacts from the Kerio Mailserver directory to a backup directory, strips the email header and changes the line endings from DOS CR/LF to *nix LF.

  • Change line endings
  • Strip email header
  • Output to new file with .vcf extension

The script is really an quick hack, it does not do any real error checking and stuff, so it can definitely die.
The script has been tested on Mac OS X but should also run on Linux. Don’t know about windoze.

#! /bin/bash 

# kerio_vcard_export.sh
# Version 1.0 Last Updated: December 4th 2006
#
# Software License Agreement
#
# Copyright (C) 2006, Simon Grasser (simeli). http://osiris.simeli.net
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Simon Grasser nor the names of its contributors
# may be used to endorse or promote products derived from this
# software without specific prior written permission of Simon Grasser.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS „AS
# IS“ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
###############################################################################
#
# You need to run the script as root to have access to the kerio files.
# The script allows to change the owner of the file to be changed – e.g.
# a non privileged user.
#

DATE=“/bin/date“

# the directory of the contacts you’d like to export
MAILSERVER=’/usr/local/kerio/mailserver/store/mail/company.com/#public/Contacts/#msgs‘

# name of the user whoe should own the exported files
OWNER=“adm“

# the directory in which you’d like to save the contacts
VCARD_DIR=’/Users/adm‘

#
# Nothing needs to be edited below this line
#

# the name of the folder in which we put the backup
# formatted with the date and time of the backup
VCARD_FOLDER=“KerioVCardBackup.`$DATE +%Y%m%d%H%M`“

# Making backup directory $VCARD_FOLDER/tmp
mkdir -p $VCARD_DIR/$VCARD_FOLDER/tmp

cd $MAILSERVER

# copy all contact files to the backup directory
cp *.eml $VCARD_DIR/$VCARD_FOLDER/tmp

# loop over all contact files in backup temp directory
cd $VCARD_DIR/$VCARD_FOLDER/tmp
for vcard in *.eml
do
echo „processing $vcard : change CR/LF, strip header“

# change DOS CR/LF to *nix line endings and strip the header of the message
# then output the „correct“ VCards to the backup directory
sed -e ’s/.$// ; 1,/^$/ d‘ <$vcard | iconv -f UTF8 -t MACROMAN > $VCARD_DIR/$VCARD_FOLDER/${vcard/%eml/vcf}
done;

# remove temporary files
rm -rf $VCARD_DIR/$VCARD_FOLDER/tmp

# change owner of the exported files
chown -R $OWNER $VCARD_DIR/$VCARD_FOLDER

Comments 3

    1. Post
      Author

      The script is over 10 years old and has not been updated ever since. So it is very likely, that it throws errors…

  1. Pingback: Convert contacts in eml to vcf - Managed IT Services London - FatMac

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.