Align Checker port resolution and add delimiter preconfig support

This commit is contained in:
Laurent Dinclaux
2026-02-10 18:38:42 +11:00
parent 39fe417104
commit 3a8202bd7a
4 changed files with 27 additions and 22 deletions

View File

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

View File

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

View File

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

View File

@@ -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,6 +101,11 @@ class IdentSwitchPreconfig
$record['ident_switch.form.common.readonly'] = $loginSet ? 2 : 1;
}
// 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;