Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Discuss
  3. Sharing custom SpamAssassin Rules

Sharing custom SpamAssassin Rules

Scheduled Pinned Locked Moved Discuss
mailspam
81 Posts 18 Posters 22.3k Views 27 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • d19dotcaD d19dotca

    @humptydumpty That's something I'd like to look into too, although I have a feeling the only thing that can really work its magic there is the Bayesian learning, so running the SpamAssassin learn commands. I've been running a script (with the help of ChatGPT, lol) like one below in case this helps as I find the Bayesian learning in Cloudron seems to be really manual or inconsistent at running (I think they've admitted that too in a post I saw somewhere the other month), and it's improved IMO with running this often. Personally I run this manually for now just because I wanted to make sure it was working, but I'll probably consider throwing this in a cron job soon enough.

    1. sudo docker exec -ti mail /bin/bash

    2. Run this script in the mail container:

    nohup bash -c '
    MAILDIR="/app/data/vmail"; SPAMD_DIR="/app/data/spamd";
    for user in $(ls "$MAILDIR"); do
        MAILBOX="$MAILDIR/$user/mail"; BAYES_PATH="$SPAMD_DIR/$user";
        mkdir -p "$BAYES_PATH"; chown -R cloudron:cloudron "$BAYES_PATH"; chmod 700 "$BAYES_PATH";
        echo "🔄 Training SpamAssassin for $user..." | tee -a /app/data/spamd/train.log;
    
        # Train spam from .Spam and .Junk folders (including subfolders)
        find "$MAILBOX/.Spam" "$MAILBOX/.Junk" -type d -name "cur" 2>/dev/null | while read folder; do
            echo "📂 Training SPAM from: $folder" | tee -a /app/data/spamd/train.log;
            sa-learn --spam --dbpath "$BAYES_PATH" --dir "$folder" | tee -a /app/data/spamd/train.log;
        done
    
        # Train ham from Inbox and Archive, but EXCLUDE Junk, Spam, Trash, Sent, and Drafts
        find "$MAILBOX" -type d -name "cur" 2>/dev/null | grep -Ev "/(\.Trash|\.Deleted Messages|\.Sent|\.Sent Messages|\.Drafts|\.Junk|\.Spam)/" | while read folder; do
            echo "📂 Training HAM from: $folder" | tee -a /app/data/spamd/train.log;
            sa-learn --ham --dbpath "$BAYES_PATH" --dir "$folder" | tee -a /app/data/spamd/train.log;
        done
    
        echo "✔ Completed training for $user! BAYES files stored in $BAYES_PATH" | tee -a /app/data/spamd/train.log;
    done;
    echo "🎉 SpamAssassin training completed for all mailboxes." | tee -a /app/data/spamd/train.log;
    ' > /app/data/spamd/train.log 2>&1 &
    

    It creates that train.log file and writes all the output to it so you can see it learning across all mailboxes for the Inbox and Archive folder as ham and the Junk/Spam folder as spam for all users. It's neat to see it saying it learned ham from 34 messages or something like that for each mailbox, haha.

    I think my latest spam rules are doing well the past week, so I'll likely be posting them here soon. 🙂

    murgeroM Offline
    murgeroM Offline
    murgero
    App Dev
    wrote last edited by
    #81

    @d19dotca Is this a good way to manually train it or do you do this to generate the rules you are making?

    --
    https://urgero.org
    ~ Professional Nerd. Freelance Programmer. ~

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Bookmarks
    • Search