Skip to content

feat(imp): add ensureImapConnection for stateless IMAP login#89

Merged
ralflang merged 4 commits into
FRAMEWORK_6_0from
feat/mail-ensure-imap-connection
Jul 8, 2026
Merged

feat(imp): add ensureImapConnection for stateless IMAP login#89
ralflang merged 4 commits into
FRAMEWORK_6_0from
feat/mail-ensure-imap-connection

Conversation

@TDannhauer

Copy link
Copy Markdown
Contributor

Summary

  • Add IMP_Auth::ensureImapConnection() to open the IMAP connection on demand.
  • Expose it via the mail API as IMP_Api::ensureImapConnection().

Motivation

Stateless entry points (ActiveSync, RPC) authenticate to Horde but do not always establish an IMAP login. With hordeauth backends this leaves imapOb() returning null, 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 (honoring full/bare), runs the imap_preauthenticate hook, then creates the base IMAP object and logs in.
  • IMP_Api::ensureImapConnection(): thin mail API wrapper delegating to IMP_Auth, so Horde_Core can call $registry->mail->ensureImapConnection() without a hard dependency on IMP.

Test plan

  • hordeauth backend: from a context without an established IMAP session, call $registry->mail->ensureImapConnection() and confirm imapOb() then returns a live client.
  • Already-connected session: confirm no-op.
  • Missing/invalid credentials: confirm Horde_Auth_Exception.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thin mail API wrapper delegating to IMP_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.

Comment thread lib/Auth.php Outdated
Comment thread lib/Auth.php
Comment thread lib/Auth.php
TDannhauer and others added 3 commits July 8, 2026 08:10
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 ralflang merged commit ae468ef into FRAMEWORK_6_0 Jul 8, 2026
1 check failed
@TDannhauer TDannhauer deleted the feat/mail-ensure-imap-connection branch July 10, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants