How to change SpamAssassin default user settings

dotcomUNDERGROUND

Verified User
Joined
Mar 31, 2022
Messages
37
How do I change the default SpamAssassin values for now users and update all existing users?

For example, I want spam mails to get delivered to spam box, delete high score spam, enable subject rewrite and set not to use attachments.
 
I use a very old method for that which I learned here from forum or docs, don't remember. Maybe it can still be found in the docs somewhere.

But it's quite easy, this is what I did.

1.) Create a user, then configure the Spamassassin settings the way you want to use them.
This wil create the following files:
/etc/virtual/domain.com/filter
/etc/virtual/domain.com/filter.conf
/home/username/.spamassassin/user.prefs

2.) Create a directory, for example in /root and give it a name for example antispam.
Now copy the above files to the /root/antispam folder. Now you have a default set of settings which you can start using.

3.) In the /usr/local/directadmin/scripts/custom directory create the following files:
user_create_post.sh with the following content:
Code:
#!/bin/sh
if [ "$spam" = "ON" ]; then
   DIR=/home/$username/.spamassassin
   mkdir  $DIR
   cp -f /root/antispam/user_prefs $DIR/user_prefs
   chown  ${username}:mail $DIR
   chmod 771 $DIR
   chown $username:$username  $DIR/user_prefs
   chmod 755 $DIR/user_prefs
   touch $DIR/spam
   chown  mail:$username $DIR/spam
   chmod 660 $DIR/spam
fi
exit 0;
Change owner to directadmin and make executable, should look like this:
-rwx------. 1 diradmin diradmin 458 2017-11-10 15:24 user_create_post.sh

As you can see above, it also works for domains, so in the same directory also create a file called domain_create_post.sh which should look like this:
-rwx------. 1 diradmin diradmin 338 2014-01-08 04:05 domain_create_post.sh
Then put the following content in there:
Code:
#!/bin/sh
cp -f /root/antispam/filter /etc/virtual/$domain/filter >/dev/null 2>&1
cp -f /root/antispam/filter.conf /etc/virtual/$domain/filter.conf >/dev/null 2>&1
chown mail:mail /etc/virtual/$domain/filter
chown mail:mail /etc/virtual/$domain/filter.conf
chmod 640 /etc/virtual/$domain/filter
chmod 600 /etc/virtual/$domain/filter.conf

Now for every new account and new domain these settings will be used.

I don't know the correct code to copy these settings for all users but you can figure it out or maybe someone else can tell you how to copy these to all existing users.
 
Last edited:
Thanks. I'll try.

I have already manually set up the existing accounts. But it will be helpful to be able change settings for all account with a command.
 
DEPRECATED: The scripts below are no longer relevant as
I read different in the thread you pointed to about the user_create_post.sh script.

So that user_create_post.sh seems still active and relevant because it handles default changes to the user_prefs file as stated in these docs. Only difference would be the .spamassassin directory would not have be made anymore and can be removed from the script.

Then in fact only the domain_create_post.sh sript would be deprectated.

If I understand English correctly then deprecated means it's older and not used anymore but does mostly does not mean it does not work anymore. If I understood correctly from the docs if you don't use the custom .json file then the old way still works. As far as I can detect on my servers, the older method indeed still does work perfectly.
Ofcourse I would like to use the modern way then too as of now.
But I can't remove all filter and filter.conf files, because those contain various settings customized by the users.

So if I understand correctly that optional template spam_defaults.json would take care that both a custom filter and filter.conf is created.
I could now make a spam_defaults.json file instead of the filter and filter.conf files. But the explanation is rather short.

At this moment my filter.conf looks like this:
Code:
high_score=15
high_score_block=yes
where=delete

And filter is kind of like this:
Code:
if
        $h_X-Spam-Level: contains "***************"
then
        seen finish
endif


if
    $h_X-Spam-Status: contains "Yes,"
then
    seen finish
endif

if error_message then finish endif

So looking at my filter and filter.conf files, how should my file look? Like this?
Code:
{
        "required_hits" : "3.5",
        "high_score" : "15",
        "high_score_block" : "yes",
        "rewrite_subject" : "1",
        "subject_tag" : "*****SPAM*****",
}

Is the required_hits pointing to the lowest score? So that would already be a custom score right? Because in DA the lowest score is 5.
Or is does the required_hits mean something else?

Now I would like to have a low score of 5 and high score of 15 and delete all spam by default.
And I want that if users change any value, my override isn't used anymore.

So I would have to set required_hits to 5 and keep the rewrite subject, but just still delete all spam mails until the user decides otherwise.

At this moment I have this working with my scripts this way. A global value is not entered as I see in DA.
But I don't see a way to make this happen in this .json file.
 
Last edited:
Back
Top