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
This commit is contained in:
usmannasir
2026-03-06 03:39:04 +05:00
parent c2c79f3967
commit 5cc423b7ae
5 changed files with 41 additions and 2 deletions

View File

@@ -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';
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';

View File

@@ -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 {

View File

@@ -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';

View File

@@ -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 {

View File

@@ -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