From 5cc423b7ae27fa14b3357000f850e997eb38aee2 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Fri, 6 Mar 2026 03:39:04 +0500 Subject: [PATCH] Fix Sieve storage: add home dir to user_query, sieve plugin paths, and mailbox autocreate - Add home directory (CONCAT) to dovecot-sql.conf.ext user_query so sieve can locate script storage per user - Add sieve/sieve_dir plugin settings to dovecot.conf templates - Add lda_mailbox_autocreate/autosubscribe so fileinto creates missing folders - Update setupSieve() upgrade function to patch all three on existing installs --- .../email-configs-one/dovecot-sql.conf.ext | 2 +- install/email-configs-one/dovecot.conf | 5 ++++ install/email-configs/dovecot-sql.conf.ext | 2 +- install/email-configs/dovecot.conf | 5 ++++ plogical/upgrade.py | 29 +++++++++++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/install/email-configs-one/dovecot-sql.conf.ext b/install/email-configs-one/dovecot-sql.conf.ext index 0fb900ce3..2dbf65a24 100644 --- a/install/email-configs-one/dovecot-sql.conf.ext +++ b/install/email-configs-one/dovecot-sql.conf.ext @@ -1,4 +1,4 @@ driver = mysql connect = host=localhost dbname=cyberpanel user=cyberpanel password=SLTUIUxqhulwsh port=3306 password_query = SELECT email as user, password FROM e_users WHERE email='%u'; -user_query = SELECT '5000' as uid, '5000' as gid, mail FROM e_users WHERE email='%u'; \ No newline at end of file +user_query = SELECT '5000' as uid, '5000' as gid, mail, CONCAT('/home/vmail/', SUBSTRING_INDEX(email, '@', -1), '/', SUBSTRING_INDEX(email, '@', 1)) as home FROM e_users WHERE email='%u'; \ No newline at end of file diff --git a/install/email-configs-one/dovecot.conf b/install/email-configs-one/dovecot.conf index bc162626c..097805e33 100644 --- a/install/email-configs-one/dovecot.conf +++ b/install/email-configs-one/dovecot.conf @@ -42,6 +42,8 @@ protocol lda { postmaster_address = postmaster@example.com mail_plugins = zlib sieve + lda_mailbox_autocreate = yes + lda_mailbox_autosubscribe = yes } protocol pop3 { @@ -77,6 +79,9 @@ plugin { zlib_save = gz zlib_save_level = 6 + sieve = ~/sieve/.dovecot.sieve + sieve_dir = ~/sieve + } service stats { diff --git a/install/email-configs/dovecot-sql.conf.ext b/install/email-configs/dovecot-sql.conf.ext index 4fd7025fa..f453b1e5a 100644 --- a/install/email-configs/dovecot-sql.conf.ext +++ b/install/email-configs/dovecot-sql.conf.ext @@ -1,4 +1,4 @@ driver = mysql connect = host=127.0.0.1 dbname=cyberpanel user=cyberpanel password=1qaz@9xvps password_query = SELECT email as user, password FROM e_users WHERE email='%u'; -user_query = SELECT '5000' as uid, '5000' as gid, mail FROM e_users WHERE email='%u'; +user_query = SELECT '5000' as uid, '5000' as gid, mail, CONCAT('/home/vmail/', SUBSTRING_INDEX(email, '@', -1), '/', SUBSTRING_INDEX(email, '@', 1)) as home FROM e_users WHERE email='%u'; diff --git a/install/email-configs/dovecot.conf b/install/email-configs/dovecot.conf index 843c43f64..c5f87f5ef 100644 --- a/install/email-configs/dovecot.conf +++ b/install/email-configs/dovecot.conf @@ -42,6 +42,8 @@ protocol lda { postmaster_address = postmaster@example.com mail_plugins = zlib sieve + lda_mailbox_autocreate = yes + lda_mailbox_autosubscribe = yes } protocol pop3 { @@ -78,6 +80,9 @@ plugin { zlib_save = gz zlib_save_level = 6 + sieve = ~/sieve/.dovecot.sieve + sieve_dir = ~/sieve + } service stats { diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 6228a2484..38770e225 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -2876,10 +2876,39 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL lda_match.group(1) + 'zlib sieve' + lda_match.group(3)) changed = True + # Add lda_mailbox_autocreate/autosubscribe for sieve fileinto + if 'lda_mailbox_autocreate' not in content: + content = re.sub( + r'(protocol lda\s*\{[^}]*mail_plugins\s*=\s*zlib sieve\n)', + r'\1 lda_mailbox_autocreate = yes\n lda_mailbox_autosubscribe = yes\n', + content) + changed = True + + # Add sieve storage settings to plugin section + if 'sieve_dir' not in content: + content = re.sub( + r'(plugin\s*\{[^}]*zlib_save_level\s*=\s*6\n)', + r'\1\n sieve = ~/sieve/.dovecot.sieve\n sieve_dir = ~/sieve\n', + content) + changed = True + if changed: with open(dovecot_conf, 'w') as f: f.write(content) + # Fix dovecot-sql.conf.ext to include home directory for sieve storage + sql_conf = '/etc/dovecot/dovecot-sql.conf.ext' + if os.path.exists(sql_conf): + with open(sql_conf, 'r') as f: + sql_content = f.read() + if 'as home' not in sql_content and "user_query" in sql_content: + sql_content = sql_content.replace( + "user_query = SELECT '5000' as uid, '5000' as gid, mail FROM e_users WHERE email='%u';", + "user_query = SELECT '5000' as uid, '5000' as gid, mail, CONCAT('/home/vmail/', SUBSTRING_INDEX(email, '@', -1), '/', SUBSTRING_INDEX(email, '@', 1)) as home FROM e_users WHERE email='%u';" + ) + with open(sql_conf, 'w') as f: + f.write(sql_content) + # Write ManageSieve config if not properly configured managesieve_conf = '/etc/dovecot/conf.d/20-managesieve.conf' write_managesieve = True