From 3a8202bd7aa84bc4496faa50ca188d66a8fed4ee Mon Sep 17 00:00:00 2001 From: Laurent Dinclaux Date: Tue, 10 Feb 2026 18:38:42 +1100 Subject: [PATCH] Align Checker port resolution and add delimiter preconfig support --- config.inc.php.dist | 4 ++++ lib/IdentSwitchChecker.php | 26 ++++++++++++-------------- lib/IdentSwitchForm.php | 3 +++ lib/IdentSwitchPreconfig.php | 16 ++++++++-------- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/config.inc.php.dist b/config.inc.php.dist index 43b43e2..f8c4fea 100644 --- a/config.inc.php.dist +++ b/config.inc.php.dist @@ -40,6 +40,10 @@ $config['ident_switch.preconfig'] = [ // Any other value is treated as 'not specified' (default). 'user' => 'email', + // IMAP folder hierarchy delimiter. + // Omit or set to null for auto-detect (recommended). + // 'delimiter' => '/', + // Are specified settings locked in interface or not. // Default - false. 'readonly' => true, diff --git a/lib/IdentSwitchChecker.php b/lib/IdentSwitchChecker.php index 232c00f..f61a997 100644 --- a/lib/IdentSwitchChecker.php +++ b/lib/IdentSwitchChecker.php @@ -112,26 +112,24 @@ class IdentSwitchChecker $imap = new rcube_imap_generic(); $host = $identity['imap_host'] ?: 'localhost'; - $port = $identity['imap_port'] ?: 143; - $ssl = false; + $ssl = null; - if (!empty($identity['flags']) && ($identity['flags'] & ident_switch::DB_SECURE_IMAP_TLS)) { - $ssl = 'tls'; - } - - // Strip and parse protocol prefix from host + // Parse scheme from host field $hostLower = strtolower($host); - if (str_starts_with($hostLower, 'tls://')) { - $ssl = 'tls'; - $host = substr($host, 6); - } elseif (str_starts_with($hostLower, 'ssl://')) { + if (str_starts_with($hostLower, 'ssl://')) { $ssl = 'ssl'; $host = substr($host, 6); - if (!$identity['imap_port']) { - $port = 993; - } + } elseif (str_starts_with($hostLower, 'tls://')) { + $ssl = 'tls'; + $host = substr($host, 6); + } elseif (!empty($identity['flags']) && ($identity['flags'] & ident_switch::DB_SECURE_IMAP_TLS)) { + // Backward compat: old records without scheme in host + $ssl = 'tls'; } + $def_port = ($ssl === 'ssl') ? 993 : 143; + $port = $identity['imap_port'] ?: $def_port; + $username = $identity['username'] ?: $identity['email']; $password = $rc->decrypt($identity['password']); diff --git a/lib/IdentSwitchForm.php b/lib/IdentSwitchForm.php index 72cf30e..7266b5b 100644 --- a/lib/IdentSwitchForm.php +++ b/lib/IdentSwitchForm.php @@ -317,6 +317,8 @@ class IdentSwitchForm if (in_array(strtoupper($cfg['user'] ?? ''), ['EMAIL', 'MBOX'])) { $record['ident_switch.form.common.readonly'] = 2; } + // Override delimiter from preconfig (auto-detect if not specified) + $record['ident_switch.form.imap.delimiter'] = $cfg['delimiter'] ?? null; } } else { $preconfig->apply($record); @@ -505,6 +507,7 @@ class IdentSwitchForm $map = [ 'ident_switch.form.imap.host' => 'imap.host', 'ident_switch.form.imap.port' => 'imap.port', + 'ident_switch.form.imap.delimiter' => 'imap.delimiter', 'ident_switch.form.imap.username' => 'imap.user', 'ident_switch.form.smtp.host' => 'smtp.host', 'ident_switch.form.smtp.port' => 'smtp.port', diff --git a/lib/IdentSwitchPreconfig.php b/lib/IdentSwitchPreconfig.php index 860dd0e..75f37ea 100644 --- a/lib/IdentSwitchPreconfig.php +++ b/lib/IdentSwitchPreconfig.php @@ -51,13 +51,8 @@ class IdentSwitchPreconfig /** * Apply preconfigured settings to an identity form record. * - * Parses IMAP and SMTP host URLs separately to extract scheme, host, - * and port, then sets the username based on the config's 'user' setting. - * - * Supports both new format (imap_host + smtp_host) and legacy format - * (single host for both). Schemes ssl:// and tls:// are handled: - * - IMAP: ssl:// is stored in host field, tls:// sets the TLS checkbox. - * - SMTP: scheme is stored directly in host field. + * Parses IMAP, SMTP, and Sieve host URLs to extract scheme, host, + * and port, then sets the username and delimiter based on config values. * * @param array $record Identity record to modify (passed by reference). * @return bool True if the preconfig is readonly, false otherwise. @@ -106,7 +101,12 @@ class IdentSwitchPreconfig $record['ident_switch.form.common.readonly'] = $loginSet ? 2 : 1; } - // Notification defaults from preconfig + // IMAP folder hierarchy delimiter (null or absent = auto-detect) + if (isset($cfg['delimiter'])) { + $record['ident_switch.form.imap.delimiter'] = $cfg['delimiter']; + } + + // Notification defaults from preconfig if (isset($cfg['notify_check'])) { $record['ident_switch.form.notify.check'] = $cfg['notify_check'] ? 1 : 0; }