<!-- NOTES - Explanation managesieve --> <!-- GOAL ONE-LINER --> <p>Filter spam (to the user-accessible <code>Junk</code> folder) server sided.</p> <!-- RATIONALE --> <p>Spam is a fact of life when it comes to e-mail. Without filtering it, spam could flood the users inboxes with unsolicited e-mails and obfuscate important e-mails, potentially to a level that it would even render the mailserver useless.</p> <p>Setting the following server sided settings offers users with a default first line of defense against having their inboxes filled up with unwanted e-mails, based on sane spam identifying criteria. The most obvious spam e-mails (having their header marked with the <code>X-Spam-Status: Yes</code> by the <a href="/mailserver/serversided-filtering-config/Mail-server_Spamfilter-configuration">spamfilter AMaViS</a>) will be filtered to the user accessible <code>Junk</code> folder.</p> <!-- NUANCE --> <blockquote> <p>:information_source: This default server behavior can be overruled by users using their client of choice.</p> </blockquote> <h2>Procedure</h2> <!-- NARRATIVE FORM --> <!-- STEP BY STEP --> <ol> <li> <p>Edit <code>/etc/dovecot/conf.d/20-lmtp.conf</code> to enable the use of plugins and add 'sieve' (the plugin to provide the actual separation of the email files and have them stored to their designated directories) to the list of plugins to use:</p> <pre><code class="language-diff"> protocol lmtp { # Space separated list of plugins to load (default is global mail_plugins). - #mail_plugins = $mail_plugins + mail_plugins = $mail_plugins sieve }</code></pre> </li> <li> <p>Edit <code>/etc/dovecot/conf.d/90-sieve.conf</code> to define the path to the directory that will contain the rule set that is to be run "after" other rules (e.g. as user-specific ones):</p> <pre><code class="language-diff"> # Identical to sieve_before, only the specified scripts are executed after the # user's script (only when keep is still in effect!). Multiple script # locations can be specified by appending an increasing number. #sieve_after = #sieve_after2 = #sieve_after2 = (etc...) + sieve_after = /etc/dovecot/sieve-after</code></pre> </li> <li> <p>Create <code>sieve-after</code> directory correspondingly:</p> <pre><code class="language-shell">mkdir /etc/dovecot/sieve-after</code></pre> </li> <li> <p>Create <code>/etc/dovecot/sieve-after/spam-to-folder.sieve</code> and populate it with the rule to filter mails that have their header marked with the <code>X-Spam-Status: Yes</code> to the <code>Junk</code> folder:</p> <pre><code class="language-diff">+ require ["fileinto","mailbox"]; + if header :contains ["X-Spam-Status"] "Yes" { + fileinto :create "Junk"; + stop; + }</code></pre> </li> <li> <p>Convert the created, human readable, .sieve file to an .svbin format that sieve "understands":</p> <pre><code class="language-shell">sievec /etc/dovecot/sieve-after/spam-to-folder.sieve</code></pre> </li> <li> <p>Restart Dovecot service to effectuate the changes:</p> <pre><code class="language-shell">service dovecot reload</code></pre> </li> </ol> <!-- REFERENCES -->