Connect. Communicate. Collaborate. Securely.

Home » Kerio User Forums » Kerio Connect » Export Contacts to VCard Shell Script
  •  
sgrasser

Messages: 6
Karma: 0
Send a private message to this user
I use Kerio Mailserver on Mac OSX and wanted to export my public contacts (about 4000). Entourage chokes when I mark all and drag them to the Desktop, and exporting in Groups of 100 is painsome. Hence I wrote the following Shell script to export the contacts. They are actually VCards in email format (i.e. with a header). It should also work on Linux without modification.

I thought I would just share this with you. Please feel free to comment.

#! /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 Edward Eliot 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 with new name
    sed -e 's/.$// ; 1,/^$/ d' <$vcard > $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

[Updated on: Mon, 04 December 2006 17:14]

  •  
campodoro74

Messages: 119
Karma: 0
Send a private message to this user
Very usefull, thank you!
  •  
sgrasser

Messages: 6
Karma: 0
Send a private message to this user
depending on the program that you wish to use the vcards with you may have to do a character encoding change with iconv

something along the lines of

    sed -e 's/.$// ; 1,/^$/ d' <$vcard | iconv -f UTF8 -t MACROMAN > $VCARD_DIR/$VCARD_FOLDER/${vcard/%eml/vcf}


you can list the available encodings with
iconv -l
Previous Topic: Subscribing to calendar in iCa
Next Topic: Will Active Directory Extensions work if the Active Directory database is moved?
Goto Forum:
  


Disclaimer:
Kerio discussion forums are intended for open communication between forum members and may contain information and material posted by members which may be useful in learning about Kerio products. The discussion forums are not intended to provide technical support for any specific product. Any information implied or expressed in the discussion forums is that of the posting member. Kerio is in no way responsible for the information posted in the forums, or its accuracy. Kerio employees may participate in the discussions, but their postings do not represent an offical position of the company on any issues raised or discussed. Kerio reserves the right to monitor and maintain the forums to promote free and accurate exchange of information.

Current Time: Sat Nov 18 00:24:31 CET 2017

Total time taken to generate the page: 0.00448 seconds
.:: Contact :: Home ::.
Powered by: FUDforum 3.0.4.