• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved Global Dovecot Sieve Rule?

G J Piper

Regular Pleskian
I'm using Plesk 12.5, running on CentOS 6.8 with Dovecot for mail.

I see that you can create custom Dovecot Sieve filters in Roundcube for each client as needed.

Can someone tell me a way (even with custom-added files) to create one "global" Dovecot sieve filter, that could maybe reside in /etc/dovecot/conf.d so it wouldn't be deleted in an upgrade, that would be in effect for all my mail users at once?

(I want to delete all email containing this header: X-Spam-Level: ***************)
 
Hey I figured it out, and it looks like I can now answer my own question, in case anyone else needs this functionality.
To enable a global email filter, when using Dovecot and Spamassassin, I was able to do it as a Dovecot Sieve, like this:

Create a new global sieve:
su root
mkdir /etc/dovecot/conf.d/custom-sieve
cd /etc/dovecot/conf.d/custom-sieve
vi /etc/dovecot/conf.d/custom-sieve/global_after.sieve

Put this, or any other sieve rules, in the above new file:
#---------------------------------------------------------
if anyof (header :contains "X-Spam-Level" "************")
{
discard;
stop;
}
#---------------------------------------------------------


Create the new global sieve configuration directive for Dovecot:
vi /etc/dovecot/conf.d/37-custom-global-sieve.conf

Put this code in the above new file:
#---------------------------------------------------------
plugin {
# Make sure to run "sievec" on this:
sieve_after = /etc/dovecot/conf.d/custom-sieve/global_after.sieve
}
#---------------------------------------------------------


Run this to compile the new sieve:
sievec /etc/dovecot/conf.d/custom-sieve/global_after.sieve

Restart the Spamassassin and Dovecot services:
service spamassassin restart
service dovecot restart

That's it!
This will run your custom global sieve filter(s) after any other personal filters each account may have.
To disable the global filter(s) for any individual accounts, simply add a new personal filter (in your Roundcube or other webmail client) that hits on all emails and simply has "Stop processing filters" as its only action.

Note: This solution works well in Plesk Onyx too! (tested in Plesk: 12.5, 17.5, 17.8, 18.0.21)
 
Last edited:
Seems like this could relatively easily be added to the main Email Server Settings in the GUI too. Hint hint, Plesk devs! ;-)
 
For an individual account, you can create a sieve filter in your webmail settings. It's quick and easy.
 
I was configuring a filter for spam flagged messages that moves it to the Spam folder.

Here is my Plesk 17.8 filter:

Code:
require ["fileinto"];

# rule:[SPAM FLAG]
if allof (header :contains "X-SPAM" "Yes")
{
        fileinto "INBOX.Spam";
        stop;
}

The flag is named X-SPAM because I'm using rspamd instead of spamassassin.
 
I make a before rule, it works fine.

37-custom-global-sieve.conf:
Code:
#---------------------------------------------------------
plugin {
# Make sure to run "sievec" on this:
sieve_before = /etc/dovecot/conf.d/custom-sieve/global_before.sieve
sieve_after = /etc/dovecot/conf.d/custom-sieve/global_after.sieve
}
#---------------------------------------------------------

global_before.sieve:
Code:
require ["fileinto"];

#---------------------------------------------------------
if anyof (header :contains "Subject" "TESTSIEVE")
{
        fileinto "INBOX.sievefilter";
        stop;
}
#---------------------------------------------------------


But how to store the mail in the mail account sievefilter?
How to set fileinto?

"/var/qmail/mailnames/domain.tld/sievefilter" do not work.

Thanks!
 
Last edited:
Code:
if anyof (header :contains "Subject" "TESTSIEVE")
{
        fileinto "INBOX.sievefilter";
        stop;
}

But how to store the mail in the mail account sievefilter?
How to set fileinto?
"/var/qmail/mailnames/domain.tld/sievefilter" do not work.
Thanks!

Instead of using:
Code:
fileinto "INBOX.sievefilter";
You would set up a destination email address of your own and put:
Code:
redirect "[email protected]";
 
Hello G J, can you please explain to me why the script begins with 37-. I did not find an explanation what the numbering means.
 
Hello G J, can you please explain to me why the script begins with 37-. I did not find an explanation what the numbering means.
It is just an arbitrary number so that the custom config file is loaded in the correct order along with the other config files found in that directory. I found it didn't work correctly unless it loaded after 15-plesk-auth.conf and before 90-plesk-sieve.conf. It could be any number between 15 and 90.
 
In your email client create a subfolder .sievefilter for account mailaccount

#---------------------------------------------------------
# -- /etc/dovecot/conf.d/37-custom-global-sieve.conf
#-- create new namespace
namespace sieveout {
separator = .
prefix = "Sieveout."
list = no
#-- location where you want, here subfolder of domain.tld/mailaccount/Maildir/
location = maildir:/var/qmail/mailnames/domain.tld/mailaccount/Maildir/
hidden = no
inbox = no
}

#---------------------------------------------------------
plugin {
# Make sure to run "sievec" on this:
sieve_before = /etc/dovecot/conf.d/custom-sieve/global-before.sieve
}
#---------------------------------------------------------

---

#---------------------------------------------------------
#-- /etc/dovecot/conf.d/custom-sieve/global-before.sieve
require ["fileinto", "mailbox"];

#test---------------------------------------------------------
if anyof (header :contains "Subject" "TESTSIEVE") {
fileinto "Sieveout.sievefilter";
stop;
}

---
- restart dovecot
- send an email to [email protected] with subject "TESTSIEVE"
- all this emails saved in /var/qmail/mailnames/domain.tld/mailaccount/Maildir/.sievefilter
 
Last edited:
The above solution works, but Sieveout and the entire content of the location is visible in all user mailboxes. I did not succeed in defining a private namespace. How can the problem be solved?

Thanks!
 
The above solution works, but Sieveout and the entire content of the location is visible in all user mailboxes. I did not succeed in defining a private namespace. How can the problem be solved? Thanks!
It would appear you have a different issue than the one I began with this thread. It may be worth writing a new discussion thread about it so you'll get more response, rather than tacking on to the bottom of this thread. Feel free to reference this thread in your new one if you choose to do so.
 
Good evening. I use PMG and if an email is spam it adds [***** SPAM *****] to the subject. How could I send these emails to the spam folder? Thanks very much
 
Back
Top