Skip to content

fix(imap_client): load slice data before persisting cache updates#47

Merged
ralflang merged 1 commit into
FRAMEWORK_6_0from
fix/staleCache
Jun 11, 2026
Merged

fix(imap_client): load slice data before persisting cache updates#47
ralflang merged 1 commit into
FRAMEWORK_6_0from
fix/staleCache

Conversation

@TDannhauer

Copy link
Copy Markdown
Contributor

fix(imap_client): load slice data before persisting cache updates

Summary

Fixes PHP 8+ Undefined array key warnings in Horde_Imap_Client_Cache_Backend_Cache::save() when IMP IMAP caching is enabled.

When a cache slice is marked for update, save() re-serializes all UIDs mapped to that slice in the slicemap. Only UIDs touched in the current request are guaranteed to be present in $this->_data[$mbox]. Accessing missing entries (e.g. UID 46751) triggers warnings on PHP 8+.

This change:

  • Loads the full slice via _loadSlice() before persisting (consistent with the existing 'add' path)
  • Skips and removes stale slicemap entries that have no corresponding cached data

Problem

PHP ERROR: Undefined array key 46751 on line 147/149 of Cache.php

Observed with IMP and 'cache' => 'cache' in backends.local.php.

Solution

foreach (array_keys(array_flip($val['slice'])) as $slice) {
    $this->_loadSlice($mbox, $slice);
    $data = [];
    foreach (array_keys($s['s'], $slice) as $uid) {
        if (!isset($d[$uid])) {
            unset($s['s'][$uid]);
            continue;
        }
        // ...
    }
}

Test plan

  • Enable IMAP caching ('cache' => 'cache') in IMP backend config
  • Open inbox and read messages that were previously triggering the warning
  • Confirm Horde log shows no Undefined array key warnings from Cache.php
  • Verify cached message metadata (flags, envelope, etc.) still loads correctly after browsing
  • Delete a message and confirm cache updates without warnings
  • Optionally flush Memcache and confirm cache rebuilds cleanly on next IMP access

When saving modified IMAP cache slices, ensure the full slice is loaded into working memory before serializing. Skip and remove stale UIDs that remain in the slicemap but have no cached data, avoiding PHP 8+
"Undefined array key" warnings in IMP.
@TDannhauer TDannhauer requested a review from ralflang June 11, 2026 12:24
@what-the-diff

what-the-diff Bot commented Jun 11, 2026

Copy link
Copy Markdown

PR Summary

  • Improvement on Data Loading
    Added a new functionality that triggers a method _loadSlice($mbox, $slice). This new feature is situated in a process that goes over a collection of 'slices' in the data, making it more efficient in fetching the relevant information.

  • Added UID Checks
    Implemented a new safeguard which checks the presence of 'uid' in the data array $d before proceeding. This is done to avoid complications and errors in case 'uid' is not available. If 'uid' is found missing, an operation ensures to clean it from the data set $s['s'][$uid] as well, promoting error-free and seamless processing.

@ralflang ralflang merged commit ac75055 into FRAMEWORK_6_0 Jun 11, 2026
0 of 6 checks passed
@TDannhauer TDannhauer deleted the fix/staleCache branch June 13, 2026 21:38
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.

2 participants