From bf20a96310a754b11ec7a49f7519078bd0884623 Mon Sep 17 00:00:00 2001 From: Torben Dannhauer Date: Wed, 8 Jul 2026 07:51:41 +0200 Subject: [PATCH 1/4] fix(activesync): guard against null IMAP client in _getImapOb() Horde_ActiveSync_Imap_Adapter::_getImapOb() returned the result of $this->_imap->getImapOb() directly. When the factory yields an empty client (e.g. no established IMAP session on a stateless or long-running request), callers such as ping() invoked status() on null and produced a fatal error. Treat an empty client like the failure path and throw Horde_Exception_AuthenticationFailure so the sync layer handles it gracefully instead of fataling. --- lib/Horde/ActiveSync/Imap/Adapter.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Horde/ActiveSync/Imap/Adapter.php b/lib/Horde/ActiveSync/Imap/Adapter.php index 4f564b24..c1f753b4 100644 --- a/lib/Horde/ActiveSync/Imap/Adapter.php +++ b/lib/Horde/ActiveSync/Imap/Adapter.php @@ -1223,10 +1223,16 @@ protected function _doQuery(array $query, array $options, bool $deepTraversal): protected function _getImapOb() { try { - return $this->_imap->getImapOb(); + $imap = $this->_imap->getImapOb(); } catch (Horde_ActiveSync_Exception $e) { throw new Horde_Exception_AuthenticationFailure('EMERGENCY - Unable to obtain the IMAP Client'); } + + if (empty($imap)) { + throw new Horde_Exception_AuthenticationFailure('EMERGENCY - Unable to obtain the IMAP Client'); + } + + return $imap; } /** From 5bdc88c008fb98b2b5e5a5a8df564143f0f80ea5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 06:06:32 +0000 Subject: [PATCH 2/4] Update _getImapOb() docblock @throws to Horde_Exception_AuthenticationFailure --- lib/Horde/ActiveSync/Imap/Adapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Horde/ActiveSync/Imap/Adapter.php b/lib/Horde/ActiveSync/Imap/Adapter.php index c1f753b4..b975800b 100644 --- a/lib/Horde/ActiveSync/Imap/Adapter.php +++ b/lib/Horde/ActiveSync/Imap/Adapter.php @@ -1218,7 +1218,7 @@ protected function _doQuery(array $query, array $options, bool $deepTraversal): * is not yet authenticated at the time of object creation. * * @return Horde_Imap_Client_Base - * @throws Horde_ActiveSync_Exception + * @throws Horde_Exception_AuthenticationFailure */ protected function _getImapOb() { From dabe78dda878d1542b60296153224415e551b86b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 06:07:01 +0000 Subject: [PATCH 3/4] fix(activesync): preserve IMAP auth exception context --- lib/Horde/ActiveSync/Imap/Adapter.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Horde/ActiveSync/Imap/Adapter.php b/lib/Horde/ActiveSync/Imap/Adapter.php index b975800b..dfc103dd 100644 --- a/lib/Horde/ActiveSync/Imap/Adapter.php +++ b/lib/Horde/ActiveSync/Imap/Adapter.php @@ -1222,14 +1222,16 @@ protected function _doQuery(array $query, array $options, bool $deepTraversal): */ protected function _getImapOb() { + $message = 'EMERGENCY - Unable to obtain the IMAP Client'; + try { $imap = $this->_imap->getImapOb(); } catch (Horde_ActiveSync_Exception $e) { - throw new Horde_Exception_AuthenticationFailure('EMERGENCY - Unable to obtain the IMAP Client'); + throw new Horde_Exception_AuthenticationFailure($message, 0, $e); } if (empty($imap)) { - throw new Horde_Exception_AuthenticationFailure('EMERGENCY - Unable to obtain the IMAP Client'); + throw new Horde_Exception_AuthenticationFailure($message); } return $imap; From 74dce989701e57b357b456f47644b011088b4956 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 06:07:32 +0000 Subject: [PATCH 4/4] test(activesync): cover null IMAP client ping failure --- test/unit/Horde/ActiveSync/ImapAdapterTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/unit/Horde/ActiveSync/ImapAdapterTest.php b/test/unit/Horde/ActiveSync/ImapAdapterTest.php index c9673eea..f213f731 100644 --- a/test/unit/Horde/ActiveSync/ImapAdapterTest.php +++ b/test/unit/Horde/ActiveSync/ImapAdapterTest.php @@ -59,6 +59,18 @@ public function testPingUsesPingWatermarkNotSyncModseq() $this->assertEquals(6000, $folder->pingModseq()); } + public function testPingThrowsAuthenticationFailureWhenImapClientIsNull() + { + $adapter = new Horde_ActiveSync_Imap_Adapter([ + 'factory' => $this->_imapFactoryFixture(null), + ]); + $folder = new Horde_ActiveSync_Folder_Imap('INBOX', Horde_ActiveSync::CLASS_EMAIL); + + $this->expectException(\Horde_Exception_AuthenticationFailure::class); + + $adapter->ping($folder); + } + public function testBug13711() { Bug13711Fixtures::setActiveSyncProtocolVersion('14.1');