How to automatically create .dovecot.sieve file in new maildirs for dspam filtering

dovecotdspamsieve

I've followed this http://sealedabstract.com/code/nsa-proof-your-e-mail-in-2-hours/ tutorial, adjusted to allow for vimbadmin3 users, to set up my mail server. Most of my adjustments come from https://github.com/opensolutions/ViMbAdmin/wiki/Mail-System-Install-on-Ubuntu

The first tutorial uses the dovecot sieve (I think) plugin to route things through dspam. sieve aparently needs a .dovecot.sieve file in the users maildir.

How can I make sure that file is created when dovecot initiates new user maildirs?

Is there a way to create the file in one location, and tell dovecot/sieve to use it on all email accounts?

The file needs to contain:

require ["regex", "fileinto", "imap4flags"];
# Catch mail tagged as Spam, except Spam retrained and delivered to the mailbox
if allof (header :regex "X-DSPAM-Result" "^(Spam|Virus|Bl[ao]cklisted)$",
      not header :contains "X-DSPAM-Reclassified" "Innocent") {
  # Mark as read
  setflag "\\Seen";
  # Move into the Junk folder
  fileinto "Spam";
  # Stop processing here
  stop;
}

I'm running Ubuntu 14.04, using dovecot and postfix. I'm creating users in vimbadmin3, so their directory is not created until their first email is received.

Thanks!

Best Answer

There is no need to create this special fiel in every Maildir, use the configuration variable sieve_before. To cite the docs:

sieve_before =

Path to a script file or a directory containing script files that need to be executed before the user's script. If the path points to a directory, all the Sieve scripts contained therein (with the proper .sieve extension) are executed. The order of execution is determined by the file names, using a normal 8bit per-character comparison.

Using sieve_default would not be the right way to go, because the script specified with this option is only used, when the user has no own script configured! Using sieve_before allows you, to always execute it, irrespective of what the user does himself.

Related Topic