Part 15. Manage messages in Dovecot. Sieve
- Details
- Category: Mail Server
- Published: Tuesday, 17 December 2019 14:11
- Written by Super User
- Hits: 1957
To manage messages in Dovecot enabled Sieve.
Sieve — this is a language for describing filtering rules for messages. It was created by Cyrusoft International, Inc./ISAMET while working on the mail server Cyrus. By writing scripts with mail processing it is possible to:
- automatically sort messages in mail folders based on certain attributes (sender, subject and others).
- Automatically delete messages based on certain attributes
- set up automatic vacation on certain emails
Email processing should take place before the email gets into the user's mailbox. In our previous settings, In our previous settings, the local delivery agent (LDA) is Postfix itself. To connect the Sieve extension, you need to translate this function into Dovecot.
Dovecot configuring as a LDA
To run Dovecot as a LDA, you must install the lmtp support package with the command
# apt install dovecot-lmtpd
Dovecot does not need to be configured
Then we will setup Postfix. We are making changes to the Postfix configuration
In /etc/postfix/main.cf file add the lines:
#we will use a filter called dovecot (the filter name is chosen arbitrarily)
#as local transport (for the lmtp protocol)
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1 #deliver messages one by one
Also, the /etc/postfix/master.cf file should describe a filter called dovecot (the name was previously given in the main.cf file). To do this, add the description lines of our filter to the end of the file
# Dovecot LDA
dovecot unix - n n - - pipe
flags=DRhu user=virtual:virtual argv=/usr/lib/dovecot/dovecot-lda -f ${sender} -a $original_recipient} -d ${user}@${nexthop}}
#Mail delivery will be done with virtual:virtual rights using the utility
#/usr/lib/dovecot/deliver
After these settings, we have the opportunity to connect Sieve.
Connect the Sieve extension to Dovecot
We’ll install the Sieve extension for Dovecot
#apt install dovecot-sieve dovecot-managesieved
dovecot-sieve — This package allows you to use Sieve functionality.
dovecot-managesieved — This package enables customers to create their own filtering rules.
The configuration file dovecot-managesieved is left unchanged, since it suits us and proceed to setup the Sieve itself.
First, in the main dovecot configuration file, we will enable Sieve support. To do this, in the /etc/dovecot/dovecot.conf file, the parameter “protocols” edit to look like:
protocols = imap sieve
In the LDA settings, we enable Sieve support, for this in the /etc/dovecot/conf.d/5-lda.conf file, the block protocol lda edit to look like:
protocol lda {
# Space separated list of plugins to load (default is global mail_plugins).
mail_plugins = $ mail_plugins sieve
}
We’ll connect this plugin to the LMTP protocol. For this in the /etc/dovecot/conf.d/20-lmtp.conf the block protocol lmtp edit to look like:
protocol lmtp {
# Space separated list of plugins to load (default is global mail_plugins).
mail_plugins = $ mail_plugins sieve
info_log_path = /var/log/dovecot-lmtp.log
}
Now we are configuring location of the Sieve rule script for users. To do this, in the /etc/dovecot/conf.d/90-sieve.conf file, we will change the relevant lines and make them look like:
sieve = /var/mail/sieve/%Ld/%n/sieve/%u.sieve # The location of the active script
sieve_dir = /var/mail/sieve/%Ld/%n/sieve
# The script folder is a script library with rules
For correct operation, both parameters must be unique for each user. When specifying a path, you can use the internal variables of Dovecot:
-
%Ld — This is part of the user's login, which is equal to the mail domain
-
%n — This is part of the user's login before @, ie username
-
%u — This is a complete user login
Also we must to create this folder and specify owner and permissions for it:
# mkdir /var/mail/sieve/
# chown virtual:virtual /var/mail/sieve/
# chmod 770 /var/mail/sieve/
After all these steps, updating and creating rules can only be done by the administrator of the mail server by editing scripts. It is much more convenient to give users the opportunity to create their own rules themselves.
Connect the managesieve plugin to the RoundCube
First, we will install a set of plugins for the RoundCube by the command:
# apt install roundcube-plugins
Next, go to /etc/roundcube/plugins/managesieve. This configuration file is empty, but it contains an instruction where to get its sample.
Execute the command
cp /usr/share/roundcube/plugins/managesieve/config.inc.php.dist /etc/roundcube/plugins/managesieve/config.inc.php
This command creates a configuration file from the sample and we will starts configuring.
Find the lines and change them according to our server:
$rcmail_config['managesieve_port'] = 4190; #Specify the port for the managesieve server
$rcmail_config['managesieve_host'] = 'localhost'; # specify location managesieve server
$rcmail_config['managesieve_auth_type'] = login; # Specify the authorization type on the
#server.
#This option is taken from the Dovecot settings
$rcmail_config['managesieve_usetls'] = false; #we’ll disable encryption support
Next in the /etc/roundcube/config.inc.php file, enable the managesieve plugin.
To do this, we find the line and bring it to the form:
$Rcmail_config ['plugins'] = array ('managesieve');
After these settings are done in the user interface of the RoundCube, the filter tab appears on the settings page, where the rules for handling messages are created.
You can buy the book "Mail server based on Postfix, Dovecot and RoundCube" in electronic form in the store