Sieve Scripts via SQL Dicts in Dovecot 2.4 not working?
Hello everyone,
I am currently working on porting the Dovecot 2.4 configuration from the latest 2.3 version.
During this process, I encountered issues with the Sieve filters, particularly those related to SQL dict mappings.
The previous (2.3) configuration looked like this and worked:
|map { pattern = priv/sieve/name/$script_nametable = sieve_before username_field = username value_field = idfields { script_name = $script_name} } map { pattern = priv/sieve/data/$idtable = sieve_before username_field = username value_field = script_data fields { id= $id} } |
This resulted in the following SQL queries on the MySQL server:
|2025-08-1511:01:29.237511SELECTid FROMsieve_after WHEREscript_name ='active'ANDusername ='frittenjonas@derlinkman.de'2025-08-1511:01:29.236416SELECTid FROMsieve_before WHEREscript_name ='active'ANDusername ='frittenjonas@derlinkman.de'|
As you can see, there are SQL mappings for |sieve_before| and |sieve_after|, alongside a local file loaded prior to the SQL settings, as they are user-based.
In Dovecot 2.3, everything worked and the scripts were executed. In 2.4, however, they no longer run.
I adapted the configuration for dict SQL mapping for Sieve filters according to the documentation:
|dict_mappriv/sieve/name/$script_name{ sql_table= sieve_before username_field = username value_field id { } # The script name field in the table to querykey_fieldscript_name { value= $script_name} } dict_map priv/sieve/data/$id{ sql_table= sieve_before username_field = username value_field script_data { } key_fieldid { value= $id} } |
This also results in the dict proxy querying the database with the same pattern as before:
|2025-08-1511:11:47.175184SELECTid FROMsieve_after WHEREscript_name ='active'ANDusername ='frittenjonas@derlinkman.de'2025-08-1511:11:47.172952SELECTid FROMsieve_before WHEREscript_name ='active'ANDusername ='frittenjonas@derlinkman.de'2025-08-1511:11:47.155786SELECTid FROMsieve_after WHEREscript_name ='active'ANDusername ='frittenjonas@derlinkman.de'2025-08-1511:11:47.136030SELECTid FROMsieve_before WHEREscript_name ='active'ANDusername ='frittenjonas@derlinkman.de'|
However, unlike in 2.3, it now queries the DB twice.
In the Sieve debug logs, I see the following:
Notably:
|Aug 1512:22:2443664c142e0a dovecot: lmtp(frittenjonas@derlinkman.de)<2407><mPFNN2AKn2hnCQAAhwrv7A>: Debug: Localdelivery failed: Temporarily unable toaccessnecessary Sieve scripts |
This line concerns me.
Here are the current Sieve script declarations:
|sieve_script before{ type= beforedriver = file path= /var/vmail/sieve/global_sieve_before.sieve } sieve_script before2 { type= beforedriver = dict name= active dict proxy { name= sieve_before sieve_script_bin_path = /var/vmail/sieve_before_bindir } } sieve_script after{ type= afterdriver = file path= /var/vmail/sieve/global_sieve_after.sieve } sieve_script after2 { type= afterdriver = dict name= active dict proxy { name= sieve_after sieve_script_bin_path = /var/vmail/sieve_after_bindir } } # Personal scripts sieve_script personal { type= personal driver = file path= ~/sieve active_path = ~/.dovecot.sieve } |
The dict proxy configuration, pointing to the dict_map SQL query above, looks like this:
|dict sieve_after { driver = sql!include/etc/dovecot/sql/dovecot-dict-sql-sieve_after.conf } dict sieve_before { driver = sql!include/etc/dovecot/sql/dovecot-dict-sql-sieve_before.conf } |
Thanks for your guidance.
Kind regards
Niklas Meyer
Maintainer of the mailcow project
Hello everyone,
I am currently working on porting the Dovecot 2.4 configuration from the latest 2.3 version.
During this process, I encountered issues with the Sieve filters, particularly those related to SQL dict mappings.
The previous (2.3) configuration looked like this and worked:
map { pattern = priv/sieve/name/$script_name table = sieve_before username_field = username value_field = id fields { script_name = $script_name } }
map { pattern = priv/sieve/data/$id table = sieve_before username_field = username value_field = script_data fields { id = $id } }
This resulted in the following SQL queries on the MySQL server:
2025-08-15 11:01:29.237511 SELECT id FROM sieve_after WHERE script_name = 'active' AND username = '[1]frittenjonas@derlinkman.de' 2025-08-15 11:01:29.236416 SELECT id FROM sieve_before WHERE script_name = 'active' AND username = '[2]frittenjonas@derlinkman.de'
As you can see, there are SQL mappings for sieve_before and sieve_after, alongside a local file loaded prior to the SQL settings, as they are user-based.
In Dovecot 2.3, everything worked and the scripts were executed. In 2.4, however, they no longer run.
I adapted the configuration for dict SQL mapping for Sieve filters according to the documentation:
dict_map priv/sieve/name/$script_name { sql_table = sieve_before username_field = username value_field id { }
The script name field in the table to query
key_field script_name { value = $script_name } }
dict_map priv/sieve/data/$id { sql_table = sieve_before username_field = username value_field script_data { } key_field id { value = $id } }
This also results in the dict proxy querying the database with the same pattern as before:
2025-08-15 11:11:47.175184 SELECT id FROM sieve_after WHERE script_name = 'active' AND username = '[3]frittenjonas@derlinkman.de' 2025-08-15 11:11:47.172952 SELECT id FROM sieve_before WHERE script_name = 'active' AND username = '[4]frittenjonas@derlinkman.de' 2025-08-15 11:11:47.155786 SELECT id FROM sieve_after WHERE script_name = 'active' AND username = '[5]frittenjonas@derlinkman.de' 2025-08-15 11:11:47.136030 SELECT id FROM sieve_before WHERE script_name = 'active' AND username = '[6]frittenjonas@derlinkman.de'
However, unlike in 2.3, it now queries the DB twice.
In the Sieve debug logs, I see the following:
[7]https://pastebin.com/PTKkLsDQ
Notably:
Aug 15 12:22:24 43664c142e0a dovecot: lmtp([8]frittenjonas@derlinkman.de)<2407><mPFNN2AKn2hnCQAAhwrv7A>: Debug: Local delivery failed: Temporarily unable to access necessary Sieve scripts
This line concerns me.
Here are the current Sieve script declarations:
sieve_script before { type = before driver = file path = /var/vmail/sieve/global_sieve_before.sieve }
sieve_script before2 { type = before driver = dict name = active dict proxy { name = sieve_before sieve_script_bin_path = /var/vmail/sieve_before_bindir } }
sieve_script after { type = after driver = file path = /var/vmail/sieve/global_sieve_after.sieve }
sieve_script after2 { type = after driver = dict name = active dict proxy { name = sieve_after sieve_script_bin_path = /var/vmail/sieve_after_bindir } }
Personal scripts
sieve_script personal { type = personal driver = file path = ~/sieve active_path = ~/.dovecot.sieve }
The dict proxy configuration, pointing to the dict_map SQL query above, looks like this:
dict sieve_after { driver = sql !include /etc/dovecot/sql/dovecot-dict-sql-sieve_after.conf }
dict sieve_before { driver = sql !include /etc/dovecot/sql/dovecot-dict-sql-sieve_before.conf }
Thanks for your guidance.
Kind regards
Niklas Meyer
Maintainer of the mailcow project
References
Visible links
- mailto:frittenjonas@derlinkman.de
- mailto:frittenjonas@derlinkman.de
- mailto:frittenjonas@derlinkman.de
- mailto:frittenjonas@derlinkman.de
- mailto:frittenjonas@derlinkman.de
- mailto:frittenjonas@derlinkman.de
- https://pastebin.com/PTKkLsDQ
- mailto:frittenjonas@derlinkman.de
participants (1)
-
Niklas Meyer