Align Checker port resolution and add delimiter preconfig support
This commit is contained in:
@@ -40,6 +40,10 @@ $config['ident_switch.preconfig'] = [
|
|||||||
// Any other value is treated as 'not specified' (default).
|
// Any other value is treated as 'not specified' (default).
|
||||||
'user' => 'email',
|
'user' => 'email',
|
||||||
|
|
||||||
|
// IMAP folder hierarchy delimiter.
|
||||||
|
// Omit or set to null for auto-detect (recommended).
|
||||||
|
// 'delimiter' => '/',
|
||||||
|
|
||||||
// Are specified settings locked in interface or not.
|
// Are specified settings locked in interface or not.
|
||||||
// Default - false.
|
// Default - false.
|
||||||
'readonly' => true,
|
'readonly' => true,
|
||||||
|
|||||||
@@ -112,26 +112,24 @@ class IdentSwitchChecker
|
|||||||
$imap = new rcube_imap_generic();
|
$imap = new rcube_imap_generic();
|
||||||
|
|
||||||
$host = $identity['imap_host'] ?: 'localhost';
|
$host = $identity['imap_host'] ?: 'localhost';
|
||||||
$port = $identity['imap_port'] ?: 143;
|
$ssl = null;
|
||||||
$ssl = false;
|
|
||||||
|
|
||||||
if (!empty($identity['flags']) && ($identity['flags'] & ident_switch::DB_SECURE_IMAP_TLS)) {
|
// Parse scheme from host field
|
||||||
$ssl = 'tls';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strip and parse protocol prefix from host
|
|
||||||
$hostLower = strtolower($host);
|
$hostLower = strtolower($host);
|
||||||
if (str_starts_with($hostLower, 'tls://')) {
|
if (str_starts_with($hostLower, 'ssl://')) {
|
||||||
$ssl = 'tls';
|
|
||||||
$host = substr($host, 6);
|
|
||||||
} elseif (str_starts_with($hostLower, 'ssl://')) {
|
|
||||||
$ssl = 'ssl';
|
$ssl = 'ssl';
|
||||||
$host = substr($host, 6);
|
$host = substr($host, 6);
|
||||||
if (!$identity['imap_port']) {
|
} elseif (str_starts_with($hostLower, 'tls://')) {
|
||||||
$port = 993;
|
$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'];
|
$username = $identity['username'] ?: $identity['email'];
|
||||||
$password = $rc->decrypt($identity['password']);
|
$password = $rc->decrypt($identity['password']);
|
||||||
|
|
||||||
|
|||||||
@@ -317,6 +317,8 @@ class IdentSwitchForm
|
|||||||
if (in_array(strtoupper($cfg['user'] ?? ''), ['EMAIL', 'MBOX'])) {
|
if (in_array(strtoupper($cfg['user'] ?? ''), ['EMAIL', 'MBOX'])) {
|
||||||
$record['ident_switch.form.common.readonly'] = 2;
|
$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 {
|
} else {
|
||||||
$preconfig->apply($record);
|
$preconfig->apply($record);
|
||||||
@@ -505,6 +507,7 @@ class IdentSwitchForm
|
|||||||
$map = [
|
$map = [
|
||||||
'ident_switch.form.imap.host' => 'imap.host',
|
'ident_switch.form.imap.host' => 'imap.host',
|
||||||
'ident_switch.form.imap.port' => 'imap.port',
|
'ident_switch.form.imap.port' => 'imap.port',
|
||||||
|
'ident_switch.form.imap.delimiter' => 'imap.delimiter',
|
||||||
'ident_switch.form.imap.username' => 'imap.user',
|
'ident_switch.form.imap.username' => 'imap.user',
|
||||||
'ident_switch.form.smtp.host' => 'smtp.host',
|
'ident_switch.form.smtp.host' => 'smtp.host',
|
||||||
'ident_switch.form.smtp.port' => 'smtp.port',
|
'ident_switch.form.smtp.port' => 'smtp.port',
|
||||||
|
|||||||
@@ -51,13 +51,8 @@ class IdentSwitchPreconfig
|
|||||||
/**
|
/**
|
||||||
* Apply preconfigured settings to an identity form record.
|
* Apply preconfigured settings to an identity form record.
|
||||||
*
|
*
|
||||||
* Parses IMAP and SMTP host URLs separately to extract scheme, host,
|
* Parses IMAP, SMTP, and Sieve host URLs to extract scheme, host,
|
||||||
* and port, then sets the username based on the config's 'user' setting.
|
* and port, then sets the username and delimiter based on config values.
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
* @param array $record Identity record to modify (passed by reference).
|
* @param array $record Identity record to modify (passed by reference).
|
||||||
* @return bool True if the preconfig is readonly, false otherwise.
|
* @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;
|
$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
|
// Notification defaults from preconfig
|
||||||
if (isset($cfg['notify_check'])) {
|
if (isset($cfg['notify_check'])) {
|
||||||
$record['ident_switch.form.notify.check'] = $cfg['notify_check'] ? 1 : 0;
|
$record['ident_switch.form.notify.check'] = $cfg['notify_check'] ? 1 : 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user