Skip to content

How to Fix Dovecot Sieve Filter Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Dovecot Sieve Filter Error. We cover key concepts, practical examples, and best practices.

Dovecot Sieve filters are not being applied to incoming emails — messages land in the inbox even though a Sieve script exists, or the script fails with a compile error.

The Problem

Jun 24 10:00:00 mail dovecot[1234]: sieve: msgid=<abc@example.com>: fileinto action: mailbox Spam does not exist.

Step-by-Step Fix

Step 1: Enable Sieve plugin

# /etc/dovecot/conf.d/90-sieve.conf
plugin {
    sieve = ~/.dovecot.sieve
    sieve_dir = ~/sieve
    sieve_global_path = /var/lib/dovecot/sieve/default.sieve
    sieve_global_dir = /var/lib/dovecot/sieve/
}

Step 2: Create a Sieve script

require ["fileinto", "reject", "vacation"];

# Move spam to Junk folder
if anyof (
    header :contains "X-Spam-Flag" "YES",
    header :contains "X-Spam-Status" "Yes"
) {
    fileinto "Junk";
    stop;
}

# Sort mailing lists
if header :matches "List-Id" "*" {
    fileinto "Lists";
    stop;
}

# Vacation auto-reply
if header :contains "subject" "Out of office" {
    discard;
    stop;
}

Step 3: Compile the Sieve script

sudo sievec /var/lib/dovecot/sieve/default.sieve

Step 4: Set up a global default script

sudo mkdir -p /var/lib/dovecot/sieve/
sudo ln -s /var/lib/dovecot/sieve/default.sieve /var/lib/dovecot/sieve/default.sieve
sudo chown -R vmail:vmail /var/lib/dovecot/sieve/

Step 5: Check Sieve logs

sudo tail -f /var/log/dovecot/sieve.log

Step 6: Test Sieve script

# Test with a sample email
sudo doveadm sieve test -u user@example.com < /tmp/test_email.txt

Prevention Tips

  • Always compile Sieve scripts after editing with sievec
  • Store scripts in a version-controlled directory
  • Use require statements for all Sieve extensions used
  • Test scripts with doveadm sieve test before deploying

Common Mistakes with sieve filter

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world DOVECOT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does Dovecot not execute my Sieve script?

The Sieve plugin is not enabled or the script path is wrong. Check that mail_plugins = $mail_plugins sieve is set in the LDA/LMTP configuration. Verify the script path: ls -la ~/.dovecot.sieve. The symlink should point to a valid Sieve file.

How do I debug Sieve script compilation errors?

Run sievec -v /path/to/script.sieve to see detailed error messages. Common errors: missing semicolons, unclosed blocks, and require statements for unused extensions. The binary output is saved to script.svbin.

Can I set per-user Sieve scripts in Dovecot?

Yes, the user manages their own script at ~/.dovecot.sieve. When a user creates this symlink pointing to their Sieve file, Dovecot automatically compiles and applies it. Use sieve_dir for the directory containing user scripts.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro