diff --git a/lib/Horde/ActiveSync/Imap/Adapter.php b/lib/Horde/ActiveSync/Imap/Adapter.php index 4f564b24..dfc103dd 100644 --- a/lib/Horde/ActiveSync/Imap/Adapter.php +++ b/lib/Horde/ActiveSync/Imap/Adapter.php @@ -1218,15 +1218,23 @@ 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() { + $message = 'EMERGENCY - Unable to obtain the IMAP Client'; + 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'); + throw new Horde_Exception_AuthenticationFailure($message, 0, $e); } + + if (empty($imap)) { + throw new Horde_Exception_AuthenticationFailure($message); + } + + return $imap; } /** 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');