Avoid competing duplicate early Email folder initialization on iOS#186
Open
thesnoopy wants to merge 17 commits intoZ-Hub:developfrom
Open
Avoid competing duplicate early Email folder initialization on iOS#186thesnoopy wants to merge 17 commits intoZ-Hub:developfrom
thesnoopy wants to merge 17 commits intoZ-Hub:developfrom
Conversation
Update 2.7.x branch from develop
Update version for autodiscover subdirectory
…2021-get-duplicated Fixed Folders created on Outlook 2021 get duplicated
fix: error `PHP message: PHP Fatal error: Uncaught Error: Attempt to assign property "body" on null`
Update mime_encode.php
fixed Z-Hub#88 PGP and S/MIME encryption
fix PHP 8.0 error ("" < -1) as there is no automatic cast anymore Syn…
Wrong encoding, conversion from "unicode-1-1-utf-7"
…content-type Radicale ignore vcard getcontenttype if Address Book collection
fixstates skip IStateMachine::BACKENDSTORAGE for delete
to use parameters to prevent SQL Injection CVE-2025-8264 as reported by Snyk and XBOW
CVE-2025-8264 - Imap - update user_identity getIdentityFromSql, to use parameters to prevent SQL Injection
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
This PR fixes a reproducible iOS Mail initial sync issue for Email folders where a second very-early fresh initialization of the same folder can arrive shortly after the first initial sync has already started making progress.
Before this change, that second early initialization could become a competing sync path instead of following the already active initial sync state. In practice this could lead to loop detection, item-by-item fallback, stalled or trickling visible progress, and generally unstable early folder sync behavior.
This PR does not disable loop detection globally.
Instead, for a narrowly scoped case only, it attaches a duplicate very-early
reqkey='0'Email folder initialization to the already running initial sync state for the same folder.Problem
Observed with iOS Mail / ActiveSync on Email folders:
In live testing this was especially visible during early sync of a large Email folder. Once the duplicate early initialization was attached to the already active sync state, normal batched sync progress resumed.
Root cause
The issue did not behave like a permanently broken message or a general IMAP export failure.
The observed behavior was instead consistent with an early duplicate initialization of the same Email collection:
The fix therefore addresses sync-state handling at the request boundary rather than weakening loop protection globally.
Fix
In
src/lib/request/sync.php, when a request arrives withreqkey='0', Z-Push now checks whether this is a very-early duplicate initialization of the same Email folder and whether there is already an active initial sync state for that folder that recently made progress.If so, the duplicate early request is attached to the already active sync key instead of creating a competing fresh initialization path.
This keeps the second early request aligned with the active sync state rather than letting it establish a separate competing startup path.
Why multiple files are changed
Although the functional core of the fix is centered around the early duplicate-init attach path in
src/lib/request/sync.php, the full patch touches several related files because the final working state was reached through investigation and then cleaned up.Current purpose of the changed files:
src/lib/request/sync.phpreqkey='0'Email folder initialization to the already active sync state for that foldersrc/lib/core/loopdetection.phpsrc/backend/imap/imap.phpsrc/lib/core/streamimporter.phpsrc/lib/default/diffbackend/diffstate.phpsrc/lib/default/diffbackend/exportchangesdiff.phpScope / safety
The behavior change is intentionally narrow:
reqkey='0'requestsEmailcollectionsWhat this PR does not do
This PR does not:
It only hardens the very-early duplicate Email folder initialization case.
Reproduction pattern
This was reproduced with a real iOS Mail client against ActiveSync:
Validation
The patch was validated against live iOS Mail behavior.
Observed after the fix:
Notes
This PR is intended as a narrow server-side hardening for iOS Mail duplicate early Email folder initialization.
The goal is not to work around arbitrary client behavior in general, but to prevent a specific early duplicate-init pattern from becoming a competing sync path while preserving normal loop protection.