Table of Contents

Note

Dovecot is a powerful mailbox manager supporting imap, imaps, pop and a multitude of plugins. It is frequently used in combination with postfix - where postfix acts as an MTA, dovecot manages the incoming e-mail, as well as serving it over different protocols. This guide explains how to use sive, a dovecot plugin, that can be used for e-mail triage.

Setup

Under Debian, postfix uses procmail to deliver e-mail but we can switch to dovecot's deliver agent and get rid of procmail altogether.

Dovecot

Dovecot needs the lda protocol enabled. This can be achieved by editing /etc/dovecot/dovecot.conf and enabling the following options:

protocol lda {
  # Address to use when sending rejection mails (e.g. postmaster@example.com).
  postmaster_address = postmaster@example.tld

  # Hostname to use in various parts of sent mails, eg. in Message-Id.
  # Default is the system's real hostname.
  hostname = example.tld
  
  # Support for dynamically loadable plugins. mail_plugins is a space separated
  # list of plugins to load.
  mail_plugins = sieve
  mail_plugin_dir = /usr/lib/dovecot/modules/lda 

  # Subject: header to use for rejection mails. You can use the same variables
  # as for rejection_reason below.
  rejection_subject = Rejected: %s

  # Human readable error message for rejection mails. You can use variables:
  #  %n = CRLF, %r = reason, %s = original subject, %t = recipient
  rejection_reason = Your message to <%t> was automatically rejected:%n%r

  # UNIX socket path to master authentication server to find users.
  auth_socket_path = /var/run/dovecot/auth-master
}

where example.tld is the hostname for which dovecot is managing e-mails.

Next, we go all the way down to the plugin section of dovecot.conf and enable sieve:

  # Sieve plugin (http://wiki.dovecot.org/LDA/Sieve) and ManageSieve service
  #
  # Location of the active script. When ManageSieve is used this is actually
  # a symlink pointing to the active script in the sieve storage directory.
  sieve=~/.dovecot.sieve

This configuration setting will allow each user for which e-mail is served to create their own .dovecot.sieve file in their home directory in order to redirect e-mail to various folders.

Postfix

Now, we can get rid of procmail by editing /etc/postfix/main.cf and replacing the line:

mailbox_command = procmail -a "$EXTENSION"

with:

mailbox_command = /usr/lib/dovecot/deliver

which will now make dovecot handle the actual delivery of e-mails to their corresponding destinations.

After this step is done, one can optionally remove procmail from the system and thereby reduce dependencies:

dpkg --purge procmail

Sieve

Now that dovecot is handling the delivery, and that sieve is going to read the .dovecot.sieve in each user's home directory, we can experiment with some sample rules:

require "fileinto";
if allof (address :is "from" "service@mail.secondlife.com",
          header :contains "Subject" "Customer") {
        fileinto "marketplace";
}
if anyof (address :contains "from" "im.agni.lindenlab.com",
                address :is "from" "service@secondlife.com") {
        fileinto "secondlife";
}
if header :contains "Subject" "Cydia/APT(A)" {
        fileinto "cydia";
}

the example above will do the following:

  • if the from field is exactly service@mail.secondlife.com, and (alloff) the subject field contains the word Customer then that e-mail will be stored in a folder called marketplace.
  • if the from field contains im.agni.lindenlab.com, or (anyof) the address is exactly service@secondlife.com then that e-mail will be stored in a folder called secondlife.

and finally:

  • if the subject field contains Cydia/APT(A) then that e-mail will be stored in a folder called cydia.

Note that these folders are created automatically if they do not exist.


networking/dovecot/filtering_emails_with_sieve.txt ยท Last modified: 2022/04/19 08:27 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.