authlibldapextractor
#!/bin/bash
# use with sourse
export `cat /etc/authlib/authldaprc | grep -v '#' | grep -v '^$' | sed 's|, *\(\w*=\)|,\1|g' | sed 's|\(\w*\)\s*\(.*\)|\1=\2|'`
make_dirs
#!/bin/bash
source /root/bin/authlibldapextractor
ldapsearch -x -H $LDAP_URI -b $LDAP_BASEDN -D $LDAP_BINDDN -w $LDAP_BINDPW $LDAP_FILTER |\
grep -i "^$LDAP_HOMEDIR:" | grep -Fv "/dev/null" | cut -d' ' -f2- | while read i; do
#echo $i
mkdir -p $i
if [[ -f "$i/Maildir" ]]; then
rm $i/Maildir
echo "$i/Maildir war removed -file, not -folder"
fi
if ! [ -e "$i/Maildir" ]; then
/usr/local/bin/maildirmake $i/Maildir
/usr/local/bin/maildirmake $i/Maildir/.Drafts
/usr/local/bin/maildirmake $i/Maildir/.Sent
/usr/local/bin/maildirmake $i/Maildir/.Templates
/usr/local/bin/maildirmake $i/Maildir/.Trash
chown -R $LDAP_GLOB_UID:$LDAP_GLOB_GID $i
echo "$i/Maildir created"
fi
done
sa-learh_watcher
#!/bin/bash
reload="10m"
trap "killall inotifywait" SIGINT SIGTERM
function parser(){
spam=$1
inbo=$2
while read dir com file; do
if [[ $dir == $spam ]]; then
echo $dir/$file moved to spam
sa-learn -u mail --spam $dir/$file
elif [[ $dir == $inbo ]]; then
echo $dir/$file moved to inbox
sa-learn -u mail --ham $dir/$file
fi
done
}
source /root/bin/authlibldapextractor
ldapsearch -x -H $LDAP_URI -b $LDAP_BASEDN -D $LDAP_BINDDN -w $LDAP_BINDPW $LDAP_FILTER |\
grep -i "^$LDAP_HOMEDIR:" | grep -Fv "/dev/null" | cut -d' ' -f2- | while read i; do
base=$i
spam="$base/Maildir/.Spam/cur/"
inbo="$base/Maildir/cur/"
echo -n "$base init... "
if [[ -e $spam ]] && [[ -e $inbo ]]; then
inotifywait -e create -m $base/Maildir/.Spam/cur $base/Maildir/cur | parser $spam $inbo &
sleep 1
else
echo "no dir"
fi
done
sleep $reload
echo "Reloading..."
killall inotifywait
exec $0