#!/bin/bash
##
## written by Alex $ 2014-06-09 (http://plugins-da.net/)
###########################################################################
## Linux Administrator at your service
## Server Management | Server Migration | Server Support | Server Setup
## Writing custom Plugins for Directadmin.
###########################################################################
##
## The script creates imap folders for all email accounts on the server
## according to this guide http://help.directadmin.com/item.php?id=358
##
for domain in `cat /etc/virtual/domains`;
do
username=`grep ^$domain: /etc/virtual/domainowners | cut -d\ -f2`
echo "[+] Working with $domain owned by $username";
for data in `cat /etc/virtual/$domain/passwd`;
do
ebox=`echo $data | cut -d\: -f1`;
maildir="`echo $data | cut -d\: -f6`/Maildir";
echo "[+][+] Working with $ebox@$domain with Maildir in $maildir";
[ -d "$maildir/.INBOX.teach-isspam" ] || mkdir -v $maildir/.INBOX.teach-isspam
[ -d "$maildir/.INBOX.teach-isnotspam" ] || mkdir -v $maildir/.INBOX.teach-isnotspam
chown -vR $username:mail $maildir/.INBOX.teach-*
chmod -v 770 $maildir/.INBOX.teach-*
c=`grep INBOX.teach-isspam $maildir/subscriptions -c`
if [ $c -eq 0 ]; then
echo INBOX.teach-isspam >> $maildir/subscriptions
fi;
c=`grep INBOX.teach-isnotspam $maildir/subscriptions -c`
if [ $c -eq 0 ]; then
echo INBOX.teach-isnotspam >> $maildir/subscriptions
fi;
done;
done;
exit 0;