Score:1

Sieve Does not Work in Postfix + Dovecot + LMTP + Virtual Mailbox Setting

lt flag

I am setting up a spam filter on my email server but cannot get sieve to sort the mails. All spams are delivered straight to the inbox despite rules written in .dovecot.sieve. In mail logs Postfix reports that spams (marked with X-Spam-Flag in their headers) are successfully delivered to maildir, and Dovecot reports no error at all. Dovecot version is 2.3.13 (89f716dc2). Please advise.

/etc/postfix/main.cf:

mailbox_transport = lmtp:unix:private/dovecot-lmtp
virtual_mailbox_domains = domain
virtual_mailbox_base = /home/vmail

/etc/dovecot/dovecot.conf:

protocols = imap lmtp

/etc/dovecot/conf.d/10-master.conf:

service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    mode = 0666
  }
}

/etc/dovecot/conf.d/10-mail.conf:

mail_home = /home/vmail/%d/%n/home
mail_location = maildir:/home/vmail/%d/%n

/etc/dovecot/conf.d/20-lmtp.conf:

protocol lmtp {
  mail_plugins = $mail_plugins sieve
}

/etc/dovecot/conf.d/90-sieve.conf:

sieve = ~/.dovecot.sieve

/home/vmail/domain.com/user1/home/.dovecot.sieve:

require ["fileinto"];

if header :contains "X-Spam-Flag" "YES" {
  fileinto "Junk";
  stop;
}
Score:1
lt flag

Solved the problem myself.

First of all when using Postfix paired with Dovecot one must explicitly tell it to use Dovecot as the deliver agent for virtual mailboxes. Postfix should send the mail to Dovecot instead of delivering it on its own like previously shown in the logs. Restart Postfix after adding this in /etc/postfix/main.cf:

virtual_transport = lmtp:unix:private/dovecot-lmtp

Next the "~" in /etc/dovecot/conf.d/90-sieve.conf means mail_location instead of mail_home. Setting sieve = ~/.dovecot.sieve caused Dovecot to give these outputs in the debug log:

Debug: sieve: include: sieve_global is not set; it is currently not possible to include `:global' scripts.
Debug: sieve: file storage: Storage path `/home/vmail/domain/user1/.dovecot.sieve' not found
Debug: sieve: storage: No default script location configured
Debug: sieve: User has no personal script
Debug: sieve: No scripts to execute: reverting to default delivery.

So I moved .dovecot.sieve to mail_location, and things started to work.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.