Index: npl/mailserver/kopano_conf/kopano_conf.build
===================================================================
--- npl/mailserver/kopano_conf/kopano_conf.build	(revision ce9f9b3a52acbfeacda94abadca9d652288647b7)
+++ npl/mailserver/kopano_conf/kopano_conf.build	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -1,1 +1,1 @@
-17
+19
Index: npl/mailserver/kopano_conf/kopano_conf.md5
===================================================================
--- npl/mailserver/kopano_conf/kopano_conf.md5	(revision ce9f9b3a52acbfeacda94abadca9d652288647b7)
+++ npl/mailserver/kopano_conf/kopano_conf.md5	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -3,7 +3,7 @@
 fd5fac3dcb59c74d9fc0994316749cf2  ./example-config/apparmor.d/usr.sbin.kopano-server
 ce5eb45e78a986fae32ebbdcbb1b844c  ./example-config/ldap.cfg
-7e293a686edc30a5f11f48dc087ff6a9  ./kopano_conf.pkg
+2dd1676443a03997c8fab6608ae032f5  ./kopano_conf.pkg
 1f5f7d6f71d47c726d70daff8100c56f  ./kopano_conf.SlackBuild
-6f0468d3014de6b1d2ecb92ce87750db  ./kopano_conf.SlackBuild.log.gz
+0daf718be28a2323996c28b670ca8a93  ./kopano_conf.SlackBuild.log.gz
 77e930e82d6aa224be14072dcc719ab8  ./root/etc/cron.weekly/kopano_clean
 c649bfb26c88c35ed95fcfec3fe6df9a  ./root/etc/kopano/archiver.cfg
@@ -25,5 +25,16 @@
 8d70ed9bb454b861ea6a18552c41c8b0  ./root/etc/kopano/spooler.cfg
 175d812699725aacf1c9d742dcc1447f  ./root/etc/kopano/unix.cfg
+6ce2e5563699ad17fad55c05b53fe743  ./root/etc/kopano/userscripts/companies_common.sh
+2c945cd88531fb7ac0a669d2a6b543e1  ./root/etc/kopano/userscripts/createcompany
+73a5e66d358f006f4ca075ac058190df  ./root/etc/kopano/userscripts/createcompany.d/00createpublic
+60d06ba29d1f693cb0cb796977643962  ./root/etc/kopano/userscripts/creategroup
+2803687659c7b39e6981107845ef7e99  ./root/etc/kopano/userscripts/createuser
+6cec16060e10eb3d5e58e2f3c3389636  ./root/etc/kopano/userscripts/createuser.d/00createstore
+767032ec8be1cd6b72de6b97cdedb0ad  ./root/etc/kopano/userscripts/deletecompany
+0afd831fa6d492040c7b6348865e7d78  ./root/etc/kopano/userscripts/deletegroup
+c036bd7796319ea10ddedfdfc6fb4441  ./root/etc/kopano/userscripts/deleteuser
+c29d775a82be55a7882f4604d0b45cd5  ./root/etc/kopano/userscripts/groups_common.sh
 17ad42acc933c223f16803b965775ae6  ./root/etc/kopano/userscripts/kopano-dspam-retrain
+c7fe673ce6498ede08ca148d66293aea  ./root/etc/kopano/userscripts/users_common.sh
 95056928c5e351a922159f93a8f57d2f  ./root/etc/kopano/zcontacts.inf
 61c38fc2330baa42b357af5c1d7cffe5  ./root/etc/php5/mapi.ini
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/companies_common.sh
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/companies_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/companies_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,24 @@
+# shell include script
+
+KOPANO_LANG="${KOPANO_USERSCRIPT_LOCALE:-${LC_MESSAGES:-en_US}}"
+PATH=/bin:/usr/local/bin:/usr/bin
+export KOPANO_LANG PATH
+
+if [ -z "${KOPANO_COMPANY_SCRIPTS}" ] ; then
+    exec >&2
+    echo "Do not execute this script directly"
+    exit 1
+fi
+
+if [ ! -d "${KOPANO_COMPANY_SCRIPTS}" ] ; then
+    exec >&2
+    echo "${KOPANO_COMPANY_SCRIPTS} does not exist or is not a directory"
+    exit 1
+fi
+
+if [ -z "${KOPANO_COMPANY}" -a -z "${KOPANO_COMPANYID}" ] ; then
+    exec >&2
+    echo "KOPANO_COMPANY and KOPANO_COMPANYID is not set."
+    exit 1
+fi
+exec "$PKGLIBEXECDIR/kscriptrun" "$KOPANO_COMPANY_SCRIPTS"
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,20 @@
+#! /bin/sh
+
+# Script that is executed whenever a new company is created in the
+# external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/createcompany.d
+# using find.  The environment variable KOPANO_COMPANY is set, but
+# beware that this string can contain any characters, so take heed to
+# correct quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  # Used on Debian in place of sysconfig
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_COMPANY_SCRIPTS=/etc/kopano/userscripts/createcompany.d
+. /etc/kopano/userscripts/companies_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany.d/00createpublic
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany.d/00createpublic	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createcompany.d/00createpublic	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+# Create a public store for the new company.
+
+PATH=$PATH:/sbin:/usr/local/sbin:/usr/sbin
+
+# The KOPANO_COMPANY variable from the server will always be in UTF-8
+# format.  The --utf8 option must be set before this value is used,
+# since the current locale isn't necessarily UTF-8.
+kopano-admin -v --utf8 -s -I "${KOPANO_COMPANY}"
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/creategroup
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/creategroup	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/creategroup	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Script that is executed whenever a new group is created in the
+# external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/creategroup.d
+# using find.  The environment variable KOPANO_GROUP is set, but
+# beware that this string can contain any characters, so take heed to
+# correct quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_GROUP_SCRIPTS=/etc/kopano/userscripts/creategroup.d
+. /etc/kopano/userscripts/groups_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Script that is executed whenever a new user is created in the
+# external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/createuser.d
+# using find.  The environment variable KOPANO_USER is set, but
+# beware that this string can contain any characters, so take heed to
+# correct quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_USER_SCRIPTS=/etc/kopano/userscripts/createuser.d
+. /etc/kopano/userscripts/users_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser.d/00createstore
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser.d/00createstore	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/createuser.d/00createstore	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,11 @@
+#! /bin/sh
+
+# Create a Kopano user for an already existing external user.  Create
+# and initialize the user's stores.
+
+PATH=$PATH:/sbin:/usr/local/sbin:/usr/sbin
+
+# The KOPANO_USER variable from the server will always be in UTF-8
+# format.  The --utf8 option must be set before this value is used,
+# since the current locale isn't necessarily UTF-8.
+kopano-admin -v --utf8 --create-store "${KOPANO_USER}" --lang "${KOPANO_LANG}"
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletecompany
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletecompany	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletecompany	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Script that is executed whenever a new company is deleted from
+# the external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/deletecompany.d
+# using find.  The environment variable KOPANO_COMPANY is set, but
+# beware that this string can contain any characters, so take heed to
+# correct quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_COMPANY_SCRIPTS=/etc/kopano/userscripts/deletecompany.d
+. /etc/kopano/userscripts/companies_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletegroup
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletegroup	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deletegroup	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Script that is executed whenever a new group is deleted from
+# the external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/deletegroup.d
+# using find.  The environment variable KOPANO_GROUP is set, but
+# beware that this string can contain any characters, so take heed to
+# correct quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_GROUP_SCRIPTS=/etc/kopano/userscripts/deletegroup.d
+. /etc/kopano/userscripts/groups_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deleteuser
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deleteuser	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/deleteuser	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Script that is executed whenever a new user is deleted from
+# the external user source, such as an Active Directory tree or
+# /etc/passwd.
+
+# This script executes all scripts in /etc/kopano/userscripts/deleteuser.d
+# using find.  The environment variable KOPANO_USER is set, but beware
+# that this string can contain any characters, so take heed to correct
+# quoting.
+
+if [ -f /usr/etc/sysconfig/kopano ]; then
+  . /usr/etc/sysconfig/kopano
+elif [ -f /usr/etc/default/kopano ]; then
+  . /usr/etc/default/kopano
+fi
+PKGLIBEXECDIR=/usr/libexec/kopano
+KOPANO_USER_SCRIPTS=/etc/kopano/userscripts/deleteuser.d
+. /etc/kopano/userscripts/users_common.sh
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/groups_common.sh
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/groups_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/groups_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,24 @@
+# shell include script
+
+KOPANO_LANG="${KOPANO_USERSCRIPT_LOCALE:-${LC_MESSAGES:-en_US}}"
+PATH=/bin:/usr/local/bin:/usr/bin
+export KOPANO_LANG PATH
+
+if [ -z "${KOPANO_GROUP_SCRIPTS}" ] ; then
+    exec >&2
+    echo "Do not execute this script directly"
+    exit 1
+fi
+
+if [ ! -d "${KOPANO_GROUP_SCRIPTS}" ] ; then
+    exec >&2
+    echo "${KOPANO_GROUP_SCRIPTS} does not exist or is not a directory"
+    exit 1
+fi
+
+if [ -z "${KOPANO_GROUP}" -a -z "${KOPANO_GROUPID}" ] ; then
+    exec >&2
+    echo "KOPANO_GROUP and KOPANO_GROUPID is not set."
+    exit 1
+fi
+exec "$PKGLIBEXECDIR/kscriptrun" "$KOPANO_GROUP_SCRIPTS"
Index: npl/mailserver/kopano_conf/root/etc/kopano/userscripts/users_common.sh
===================================================================
--- npl/mailserver/kopano_conf/root/etc/kopano/userscripts/users_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
+++ npl/mailserver/kopano_conf/root/etc/kopano/userscripts/users_common.sh	(revision a2d969e7ad0485dba4b6e18761e3d62cb5e85588)
@@ -0,0 +1,24 @@
+# shell include script
+
+KOPANO_LANG="${KOPANO_USERSCRIPT_LOCALE:-${LC_MESSAGES:-C}}"
+PATH=/bin:/usr/local/bin:/usr/bin
+export KOPANO_LANG PATH
+
+if [ -z "${KOPANO_USER_SCRIPTS}" ] ; then
+    exec >&2
+    echo "Do not execute this script directly"
+    exit 1
+fi
+
+if [ ! -d "${KOPANO_USER_SCRIPTS}" ] ; then
+    exec >&2
+    echo "${KOPANO_USER_SCRIPTS} does not exist or is not a directory"
+    exit 1
+fi
+
+if [ -z "${KOPANO_USER}" -a -z "${KOPANO_STOREGUID}" ] ; then
+    exec >&2
+    echo "KOPANO_USER and KOPANO_STOREGUID is not set."
+    exit 1
+fi
+exec "$PKGLIBEXECDIR/kscriptrun" "$KOPANO_USER_SCRIPTS"
