-
Notifications
You must be signed in to change notification settings - Fork 1
/
first_run.sh
101 lines (81 loc) · 2.48 KB
/
first_run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# @description Installs the spamassassin sa-learn scripts for every DirectAdmin e-mail account.
# @author Daniel Koop <[email protected]>
# @link http://danielkoop.me/portfolio-item/directadmin-spamassassin-sa-learn-every-user/
# @copyright Daniel Koop 2016
# Create for every DirectAdmin system account the teach spam folders.
create_teachspam_folder_for_every_directadmin_user()
{
for user in `ls /usr/local/directadmin/data/users`;
do
echo "
Working on DirectAdmin user $user
";
create_teach_folders /home/$user/Maildir $user;
create_teachspam_folder_for_every_domain_of_user $user;
done;
}
# Create for every domain the teach spam folders
create_teachspam_folder_for_every_domain_of_user()
{
user=${1};
# Loop through every domain
for domain in `cat /usr/local/directadmin/data/users/$user/domains.list`
do
echo "Working on domain $domain"
create_teachspamfolder_for_email_accounts_in_domain $domain $user;
echo ${domain};
done
}
create_teachspamfolder_for_email_accounts_in_domain()
{
domain=${1};
user=${2};
for raw_account_data in `cat /etc/virtual/$domain/passwd`;
do
emailbox_name=`echo $raw_account_data | cut -d\: -f1`;
maildir="`echo $raw_account_data | cut -d ':' -f6`/Maildir";
echo "Working on email box $emailbox_name@$domain"
create_teach_folders $maildir $user;
done;
}
create_teach_folders()
{
maildir=${1};
user=${2};
if [ ! -d $maildir ];
then
mkdir $maildir;
touch $maildir/subscriptions
chown $user:mail $maildir -R;
fi;
if [ ! -d "$maildir/subscriptions" ];
then
touch $maildir/subscriptions
fi;
if [ ! -d "$maildir/.INBOX.teach-isspam" ];
then
# echo "Creating teach-isspam for $maildir/.INBOX.teach-isspam";
mkdir $maildir/.INBOX.teach-isspam;
fi
if [ ! -d "$maildir/.INBOX.teach-isnotspam" ];
then
# echo "Creating teach-isspam for $maildir/.INBOX.teach-isnotspam";
mkdir $maildir/.INBOX.teach-isnotspam;
fi
chown $user:mail $maildir/.INBOX.teach-isspam;
chown $user:mail $maildir/.INBOX.teach-isnotspam;
# Inspired by https://help.poralix.com/articles/script-for-bulk-create-of-sa-teach-folders
c=`grep INBOX.teach-isspam $maildir/subscriptions -c`
if [ $c == 0 ]; then
echo INBOX.teach-isspam >> $maildir/subscriptions
fi;
c=`grep INBOX.teach-isnotspam $maildir/subscriptions -c`
if [ $c == 0 ]; then
echo INBOX.teach-isnotspam >> $maildir/subscriptions
fi;
chown $user:mail $maildir -R;
}
# Run the scripts
create_teachspam_folder_for_every_directadmin_user;
exit 0;