Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions lib/Horde/Core/ActiveSync/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,50 @@ public function authenticate($username, $password, $domain = null)
}
}

if (!$this->_ensureMailAuthenticated($username, $password)) {
return Horde_ActiveSync::AUTH_REASON_UNAVAILABLE;
}

return true;
}

/**
* Ensure the mail backend session exists when email sync is enabled.
*
* ActiveSync authenticates to Horde; mail operations need a separate
* login to the mail app (including hordeauth transparent login to the
* IMAP backend). Delegated to the registered 'mail' application via the
* optional 'mail/ensureImapConnection' API method, so Core stays
* agnostic of the concrete mail app.
*
* @param string $username The authenticated Horde username.
* @param string $password The ActiveSync password.
*
* @return boolean True if mail is not required or the connection is ready.
*/
protected function _ensureMailAuthenticated($username, $password)
{
global $registry;

if (empty($this->_imap)
|| !$registry->hasMethod('mail/ensureImapConnection')) {
return true;
}

try {
$registry->mail->ensureImapConnection([
'userId' => $username,
'password' => $password,
]);
} catch (Horde_Exception $e) {
$this->_logger->warn(sprintf(
'ActiveSync: mail server authentication failed for user %s: %s',
$username,
$e->getMessage()
));
return false;
}

return true;
}

Expand Down
14 changes: 14 additions & 0 deletions lib/Horde/Core/ActiveSync/Imap/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ public function getImapOb()
} catch (Horde_Exception $e) {
throw new Horde_ActiveSync_Exception($e);
}

if (empty($this->_adapter)
&& $GLOBALS['registry']->hasMethod('mail/ensureImapConnection')) {
try {
$GLOBALS['registry']->mail->ensureImapConnection();
$this->_adapter = $GLOBALS['registry']->mail->imapOb();
} catch (Horde_Exception $e) {
throw new Horde_ActiveSync_Exception($e);
}
}
}

if (empty($this->_adapter)) {
throw new Horde_ActiveSync_Exception('IMAP client is not available.');
}

return $this->_adapter;
Expand Down
Loading