From 54091d76bad5761602663c2698a0cdca33461cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean=20Charles=20Del=C3=A9pine?= Date: Mon, 20 Jul 2026 09:21:49 +0200 Subject: [PATCH] fix(auth): honor session-stored server selection in getAutoLoginServer() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Companion to horde/base's login.php change: base now stores posted per-app login params (raw, ungrouped by meaning) in the session after a successful Horde-level login, regardless of which auth driver handled it. Read imp's own 'imp_server_key' field from there and prefer it over the existing preferred/first-backend fallback, so a server chosen on the login screen actually takes effect — even when Horde authenticated via LDAP/SQL rather than through imp itself. --- lib/Auth.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/Auth.php b/lib/Auth.php index 6897aca81..fab970607 100644 --- a/lib/Auth.php +++ b/lib/Auth.php @@ -255,11 +255,27 @@ protected static function _log($status, $imap_ob) */ public static function getAutoLoginServer() { + global $session; + if (($servers = IMP_Imap::loadServerConfig()) === false) { return null; } + // Honor a server explicitly selected on the Horde login screen, even + // when Horde itself authenticated through a driver unrelated to IMP + // (LDAP, SQL, ...). horde/base's login.php stores raw posted values + // per app in the session; only IMP interprets the 'imp_server_key' + // field. + $login_params = $session->exists('horde', 'login_app_params') + ? $session->get('horde', 'login_app_params') + : []; + $selected = $login_params['imp']['imp_server_key'] ?? null; + if (!empty($selected) && isset($servers[$selected])) { + return $selected; + } + $server_key = null; + foreach ($servers as $key => $val) { if (is_null($server_key) && (substr($key, 0, 1) != '_')) { $server_key = $key;