feat(imp): add ensureImapConnection for stateless IMAP login#89
Merged
Conversation
Stateless entry points (ActiveSync, RPC) authenticate to Horde but, with hordeauth backends, still need an explicit IMAP login that authenticate() does not guarantee outside the interactive login flow. Add IMP_Auth::ensureImapConnection(), which opens the mail server connection on demand, resolving hordeauth credentials from the session when none are supplied. Expose it through the 'mail' API (IMP_Api::ensureImapConnection()) so Horde_Core can trigger the login via the registry without depending on IMP directly.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an explicit “connect/log in to IMAP if needed” entry point for stateless callers (e.g., ActiveSync/RPC) that may have Horde authentication without an initialized IMP IMAP client, and exposes it through the mail API for use by Horde_Core without a direct IMP dependency.
Changes:
- Add
IMP_Auth::ensureImapConnection(array $credentials = [])to initialize the IMAP client and perform login on demand. - Add
IMP_Api::ensureImapConnection()as a thinmailAPI wrapper delegating toIMP_Auth.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/Auth.php | Adds the new on-demand IMAP connection/login helper for stateless entry points. |
| lib/Api.php | Exposes the helper via the mail API to avoid hard dependencies on IMP. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
ralflang
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IMP_Auth::ensureImapConnection()to open the IMAP connection on demand.mailAPI asIMP_Api::ensureImapConnection().Motivation
Stateless entry points (ActiveSync, RPC) authenticate to Horde but do not always establish an IMAP login. With
hordeauthbackends this leavesimapOb()returningnull, breaking mail features that assume a live client.IMP_Auth::authenticate()is tied to the interactive login flow and returns early when a client already exists, so it is not a reliable way to force a connection from these entry points.Changes
IMP_Auth::ensureImapConnection(array $credentials = []): no-op if already initialised; otherwise resolves the auto-login server, fills hordeauth credentials from the session (honoringfull/bare), runs theimap_preauthenticatehook, then creates the base IMAP object and logs in.IMP_Api::ensureImapConnection(): thinmailAPI wrapper delegating toIMP_Auth, soHorde_Corecan call$registry->mail->ensureImapConnection()without a hard dependency on IMP.Test plan
$registry->mail->ensureImapConnection()and confirmimapOb()then returns a live client.Horde_Auth_Exception.