rspamd and learning

chrismfz

Verified User
Joined
Jul 3, 2019
Messages
33
I know I need redis server first, learned the hard way. After that, how do I learn ham and spam ?
I tried with rspamc ham and I am getting:

Results for file: 1607590859.M996168P1267448xxx,S=6193,W=6295:2,Sa (0.001 seconds)
IO write error: Connection refused

Results for file: 1607589962.M214993P1250672.xxx,S=4282,W=4369:2,Sa (0.001 seconds)
IO write error: Connection refused

Results for file: 1607505042.M47497P520266.xxx,S=6513,W=6617:2,S (0.001 seconds)
IO write error: Connection refused

Also I saw that it can learn with imapSieve:

Anyone tried it ? Should wait for implementation or I hope for too much? ?

Also copying mail's id in rspamd web ui "scan mail" doesn't help for learning ham / spam. I need the full source.
Something that's not possible for various reasons when we talk about user's mails.
Loading the ID I am getting
Data successfully uploaded
×contains less tokens than required for bayes classifier: 3 < 11

I have to load full source to get something to ham/spam.
Anyone using another way ?
 
I have the same issue and after 5 years no any solution, why we get the
IO write error: Connection refused error ?
I have made some search on internet but could not find any solution any thought on this ?

EDIT: for future reference here is the solution :
Code:
rspamc -h /var/run/rspamd/rspamd_controller.sock learn_spam /home/username/imap/username.com/info/Maildir/.Junk/cur

I am not an programmer but with help of Chatgpt i have created this bash to scan all the users mail box junk folder to learn and afterwards delete the junk mail

Bash:
#!/bin/bash

# Base directory where user mail is stored
MAIL_ROOT="/home"

# Rspamd controller socket
RSPAMD_SOCKET="/var/run/rspamd/rspamd_controller.sock"

# Log file location
LOG_FILE="/var/log/rspamd/train_spam.log"

# Timestamp for the log
echo "========== $(date '+%Y-%m-%d %H:%M:%S') ==========" >> "$LOG_FILE"

# Find all .Junk/cur folders under all users and domains
find "$MAIL_ROOT" -type d -path "*/imap/*/*/Maildir/.Junk/cur" | while read -r junk_folder; do
    if [ "$(ls -A "$junk_folder")" ]; then
        echo "Training on: $junk_folder" | tee -a "$LOG_FILE"
     
        # Run Rspamd training
        if rspamc -h "$RSPAMD_SOCKET" learn_spam "$junk_folder" >> "$LOG_FILE" 2>&1; then
            echo "Training successful. Deleting messages..." | tee -a "$LOG_FILE"
            rm -f "$junk_folder"/*
        else
            echo "Training FAILED for: $junk_folder" | tee -a "$LOG_FILE"
        fi
    else
        echo "No messages to train in: $junk_folder" | tee -a "$LOG_FILE"
    fi
done

Can anyone confirm if this script is ok and safe ?
 
Last edited:
You can use the script from Poralix
That is what I am using already on some of our servers with Spamassassin but didn't dear to use it with rSpamd :)

So if I understand correctly when users move spam to teach-isspam folder the rSpamd database (Redis) will be populated automatically for all the users ?
 
Last edited:
So if I understand correctly when users move spam to teach-isspam folder the rSpamd database (Redis) will be populated automatically for all the users ?

the scripts run with cron, and are not triggered on "emails move" actions. rSpamd uses global databases of hashes, and it does not differentiate them on user's bases. So all hashes will be used for all existing users.
 
Back
Top