Sieve is a script to manage email delivery within the mailbox.
e.g. An email with X-Spam: Yes header will be delivered to the Junk folder.

WARNING: Dovecot has breaking changes in the configuration between 2.3 and 2.4. Be sure to update the configuration files according to the version you are using.

Install

sudo apt install dovecot-sieve dovecot-managesieved
  • dovecot-sieve: Sieve plugin for Dovecot LMTP
  • dovecot-managesieved: Enables per-user Sieve script management

Open the port for managesieved

sudo firewall-cmd --add-service=managesieve --permanent
sudo firewall-cmd --reload

Configure

Edit the mail plugin line in /etc/dovecot/conf.d/20-lmtp.conf to enable the Sieve plugin.

protocol lmtp {
  mail_plugins {
    sieve = yes
  }
}

Reload dovecot.

sudo systemctl reload dovecot

Editing Sieve scripts

As described above, each user can manage their scripts.

  • Sieve Editor: A standalone Sieve Editor
  • Roundcube: A webmail system with the built-in plugin to manage Sieve scripts

Sieve script examples

Sieve Editor notice

  • Create a script and “activate” it to apply the rules

Dovecot dbox notice

The directory separator differs between Maildir and dbox (Dovecot sdbox/mdbox).

  • Maildir: “.(period)”
  • dbox: “/”

For example, folder01 under INBOX location is

Maildir style:

require "fileinto";

if header :contains "from" "folder01@example.com" {
  fileinto "INBOX.folder01";
}

dbox style:

require "fileinto";

if header :contains "from" "folder01@example.com" {
  fileinto "INBOX/folder01";
}