Solved Move email message automatic to junk Folder

souzadavi

New member
Joined
May 26, 2022
Messages
4
Hello,how to make my sieve file run when new messages arrived and have SPAM added header from rspamd and move this message to Junk folder automatic?

1751843499569.png

I'm using Dovecot 2.4.1 with Rspamd, spamassassin is disabled. Rspamd Added and learned the spam already. But the message with Sieve imapsieve plugin for Pigeonhole version 2.4.1-4.

The email header is:

Code:
X-Spam-Status: Yes, score=7.2, +20 total spam score
X-Spam-Bar: +++++++
SpamTally: Final spam score: 81

But it still on INBOX not moving to Junk folder


Screenshot from 2025-07-06 18-09-29.png

my spam-to-junk.sieve
Code:
require ["fileinto"];

# Detectar spam por X-Spam-Status
if header :contains "X-Spam-Status" "Yes" {
    fileinto "Junk";
    stop;
}

When do a sievec spam-to-junk.sieve the output is:

Code:
[root@da dovecot-sieve]# sievec spam-to-junk.sieve
sievec(root)<29051><>: Debug: Loading modules from directory: /usr/lib64/dovecot
sievec(root): Debug: Effective uid=0, gid=0, home=/root
sievec(root): Debug: sieve: Pigeonhole version 2.4.1-4 (0a86619f) initializing
sievec(root): Debug: sieve: Sieve imapsieve plugin for Pigeonhole version 2.4.1-4 (0a86619f) loaded
sievec(root): Debug: sieve: vnd.dovecot.filter extension: No bin or socket directory specified; extension is unconfigured (both sieve_vnd.dovecot.filter_bin_dir and sieve_vnd.dovecot.filter_socket_dir are not set)
sievec(root): Debug: sieve: vnd.dovecot.execute extension: No bin or socket directory specified; extension is unconfigured (both sieve_vnd.dovecot.execute_bin_dir and sieve_vnd.dovecot.execute_socket_dir are not set)
sievec(root): Warning: sieve: ignored unknown extension 'spam-to-junk' while configuring available extensions
sievec(root): Debug: sieve: Sieve script storage 'spam-to-junk.sieve' not found (cause=any)
sievec(root): Debug: sieve: storage _file: file: Using Sieve script path: /usr/local/bin/dovecot-sieve/spam-to-junk.sieve
sievec(root): Debug: sieve: storage _file: file: script 'spam-to-junk': Opened from '_file'
sievec(root): Debug: sieve: storage _file: file: script 'spam-to-junk': Opened script for reading
sievec(root): Debug: sieve: Script '_file/spam-to-junk' successfully compiled
sievec(root): Debug: sieve: storage _file: file: script 'spam-to-junk': Saving binary to '/usr/local/bin/dovecot-sieve/spam-to-junk.svbin'
sievec(root): Debug: sieve: storage _file: file: script 'spam-to-junk': Closed script
sievec(root): Debug: User session is finished

I created the filhe: vi /etc/dovecot/conf.d/99-imap-sieve.conf
Code:
cat /etc/dovecot/conf.d/99-imap-sieve.conf
protocol imap {
    mail_plugins {
        imap_sieve = yes
    }
}

sieve_plugins {
    sieve_imapsieve   = yes
    sieve_extprograms = yes
}

sieve_global_extensions {
    vnd.dovecot.pipe = yes
    vnd.dovecot.filter = yes
    vnd.dovecot.execute = yes
    vnd.dovecot.environment = yes
}

sieve_pipe_bin_dir = /usr/local/bin/dovecot-sieve

namespace inbox {
    mailbox Junk {
        sieve_script report-spam {
            type  = before
            cause = copy
            path  = /usr/local/bin/dovecot-sieve/report-spam.sieve
        }
    }
    imapsieve_from Junk {
        sieve_script report-ham {
            type  = before
            cause = copy
            path  = /usr/local/bin/dovecot-sieve/report-ham.sieve
        }
    }
}

Code:
# cat /etc/dovecot/conf.d/15-mailboxes.conf
namespace inbox {
    type = private
    separator = .
    prefix =
    inbox = yes

    mailbox Drafts {
        special_use = \Drafts
        auto = subscribe
    }

    mailbox Junk {
        special_use = \Junk # autocreate Junk, but don't autosubscribe
        auto = create
        fts_autoindex = no
    }

    mailbox spam {
        special_use = \Junk
        auto = no
        fts_autoindex = no
    }

    mailbox Spam {
        special_use = \Junk
        auto = no
        fts_autoindex = no
    }

    mailbox Trash {
        special_use = \Trash
        auto = subscribe
        fts_autoindex = no
    }

    mailbox Sent {
        special_use = \Sent
        auto = subscribe
    }

    mailbox "Sent Messages" {
        special_use = \Sent
        auto = no
    }

    mailbox "Sent Items" {
        special_use = \Sent
        auto = no
    }

    mailbox Archive {
        special_use = \Archive
        auto = no
    }

    mailbox "Archives" {
        special_use = \Archive
        auto = no
    }
}

any info will be appreciated! thanks
 
Thanks for your quickly anwser @zEitEr , but I didn't figure out how to make it globally, so all the directadmin user account has it setup as default. Do you know how to do it?

thanks
 
That's on the same page in the guide:

- https://docs.directadmin.com/other-...html#how-to-enable-spamassassin-for-new-users
- https://docs.directadmin.com/other-...to-enable-spamassassin-for-existing-customers
- https://docs.directadmin.com/other-...nge-the-default-spam-settings-for-new-domains

The instructions are the same for rSpamd and SpamAssassin. Probably DA developers will rename SpamAssassin to Antispam or anything more common, that would not confuse.

ps. Kindly read the pages offered in a reply first)
 
@zEitEr thank you very much!!! Yes, I was confusion because the docs said Spamassasim so I was deep inside of sieve configuration, 2 long nights to fix it in 2 minutos with your information!

Solution info: https://docs.directadmin.com/change...nning-will-be-activated-by-default-if-allowed

The trick is done creating this single file:
/usr/local/directadmin/data/templates/custom/spam_defaults.json

Code:
{
        "where" : "userspamfolder"
}


have good week!
 
Back
Top