-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrspamd-learn-helper.sh
66 lines (55 loc) · 2.12 KB
/
rspamd-learn-helper.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
#!/bin/bash
#
# Script Name : rspamd-learn-helper.sh
# Description : Script for training SPAM and HAM for rspamd
# This script searches for ".SpamTraining" and ".HamTraining"
# folders under user directories in "/home" directory.
# Author : https://github.com/filipnet
# License : BSD 3-Clause "New" or "Revised" License
# ======================================================================================
# Set the home directory
home_directory="/home"
# Define the SPAM folder (Note: For dovecot, a dot should be prefixed to the folder name)
spam_folder=".TrainingSpam"
# Define the HAM folder (Note: For dovecot, a dot should be prefixed to the folder name)
ham_folder=".TrainingHam"
# Recursive function to search for the SPAM and HAM folders
search_training_folder() {
local directory="$1"
local folder_name="$2"
# Check if the training folder exists
if [ -d "$directory/$folder_name" ]; then
# Echo in yellow color
echo -e "\e[1;33m$folder_name folder found in $directory\e[0m"
# Execute rspamc learn command with the correct training folder name
if [ "$folder_name" == "$spam_folder" ]; then
rspamc learn_spam "$directory/$folder_name"
elif [ "$folder_name" == "$ham_folder" ]; then
rspamc learn_ham "$directory/$folder_name"
fi
fi
# Iterate through subdirectories
for subdirectory in "$directory"/*; do
if [ -d "$subdirectory" ]; then
search_training_folder "$subdirectory" "$folder_name"
fi
done
}
# Check if rspamc is available
if command -v rspamc &> /dev/null; then
echo -e "\e[1;32mrspamd is installed. Ready to train SPAM and HAM.\e[0m"
sleep 3
else
echo -e "\e[1;31mError: rspamc command not found. Please install rspamd to use this script.\e[0m"
exit 1
fi
# Iterate through user directories under /home
for user_directory in "$home_directory"/*; do
if [ -d "$user_directory" ]; then
username=$(basename "$user_directory")
# Search for SPAM folder
search_training_folder "$user_directory" "$spam_folder"
# Search for HAM folder
search_training_folder "$user_directory" "$ham_folder"
fi
done