How to Fix Dovecot Sieve Filter Error
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
requirestatements for all Sieve extensions used - Test scripts with
doveadm sieve testbefore deploying
Common Mistakes with sieve filter
- Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro