#!/bin/sh systempass="your_system_password" # the userPassword of dn: system-leave systemleave="system-leave" # e.g. ou=System,o=company accountleave="account-leave" # e.g. ou=Tokelau,o=company ldappersonaldirs=`ldapsearch -x -w $systempass -D "$systemleave" -b "$accountleave" "(accountStatus=active)" mailMessageStore | grep "^[^#]" | grep mailMessageStore | awk '{ print $2 }'` ldapshareddirs=`ldapsearch -x -w $systempass -D "$systemleave" -b "$accountleave" "(accountStatus=shared)" mailMessageStore | grep "^[^#]" | grep mailMessageStore | awk '{ print $2 }'` # create personal mailfolders for ldappersonaldir in $ldappersonaldirs do if [ ! -d $ldappersonaldir ] then mkdir -p `dirname $ldappersonaldir` maildirmake $ldappersonaldir fi done for ldapshareddir in $ldapshareddirs do ldapsharedmaildir=`dirname $ldapshareddir | sed 's/\/shared\//\/shared\.maildirs\//g'` shared_dn=`ldapsearch -x -w $systempass -D "$systemleave" -b "$accountleave" "(mailMessageStore=$ldapshareddir)" uid | grep "^[^#]" | grep "^dn:" | sed 's/^dn: //g'` shared_uid=`ldapsearch -x -w $systempass -D "$systemleave" -b "$accountleave" "(mailMessageStore=$ldapshareddir)" uid | grep "^[^#]" | grep "^uid:" | sed 's/^uid: //g'` shared_boxes=`ldapsearch -x -w $systempass -D "$systemleave" -b "$accountleave" "(mailMessageStore=$ldapshareddir)" postOfficeBox | grep "^[^#]" | grep "^postOfficeBox:" | sed 's/^postOfficeBox: //g'` shared_cn=`ldapsearch -x -w $systempass -D "$systemleave" -b "$accountleave" "(mailMessageStore=$ldapshareddir)" cn | grep "^[^#]" | grep "^cn:" | sed 's/^cn: //g'` subscribed_dirs=`ldapsearch -x -w $systempass -D "$systemleave" -b "$accountleave" "(&(accountStatus=active)(seeAlso=$shared_dn))" mailMessageStore | grep "^[^#]" | grep mailMessageStore | awk '{ print $2 }'` # create shared mailfolder if [ ! -d $ldapsharedmaildir ] then maildirmake -S $ldapsharedmaildir fi # create shared subfolders if [ ! -d $ldapsharedmaildir/.$shared_uid ] then maildirmake -s write -f $shared_uid $ldapsharedmaildir fi # create other shared subfolders for box in $shared_boxes do if [ ! -d $ldapsharedmaildir/.$box ] then maildirmake -s write -f $box $ldapsharedmaildir fi done # mailstorage directory if [ ! -d $ldapshareddir ] then mkdir -p `dirname $ldapshareddir` fi # link mailstorage to incoming shared folder dirlink=`echo $ldapshareddir | sed 's/\/$//g'` if [ ! -L $dirlink ] then ln -s $ldapsharedmaildir/.$shared_uid $dirlink fi # subscribe those who have a 'seeAlso' to the dn of the shared account for subscribed_dir in $subscribed_dirs do groupname=`echo $shared_cn | sed 's/ /_/g'` subscribed=$groupname if [ -e $subscribed_dir/shared-maildirs ] then subscribed=`cat $subscribed_dir/shared-maildirs | grep ^$groupname[[:space:]] | awk '{ print $1 }'` fi if [ ! $subscribed ] then maildirmake --add $groupname=$ldapsharedmaildir $subscribed_dir fi done done