Repository navigation
fix(email-links): right Mail account from the sidebar; links follow moved mail and go when it is deleted - #11598
Draft
rubenvdlinde wants to merge 6 commits into
Draft
rubenvdlinde wants to merge 6 commits into
rubenvdlinde wants to merge 6 commits into
Conversation
Mail 5's path URLs (/apps/mail/box/{mailbox}/thread/{message}) do not
name the account, so the observer assumed account 1 for every thread
and read a mailbox id as the account id for /box/{mailbox}. Any user
whose Mail account is not id 1, or who has several accounts, got
links and lookups made against the wrong account, or a 403 from the
ownership check.
The observer now asks Mail which mailbox the open message is in and
which account owns that mailbox, and publishes account and message id
together, so a tab never loads a message under a missing or stale
account. When Mail cannot answer, the account stays empty and the
tabs do nothing rather than act on a guess.
Assisted-by: ClaudeCode:claude-opus-5-5
Nothing listened to Mail's delete events, so a link kept pointing at a Mail message id after the message was deleted. The object then listed mail nobody could open, and the dead id could never be cleaned up. Mail's MessageDeletedEvent carries the account, the mailbox and the IMAP uid, not the database id, and it also fires on a move (including to the trash), where the message row keeps its id. So the listener does not trust the event to name the gone message: it reconciles the account's links against the rows Mail still stores. A link whose row survives is left alone. A link whose row is gone moves to another stored copy of the same mail (same RFC Message-ID) in the same account, because the link is about the mail, not one copy of it; copies in other accounts are not used, since every read of a link checks the ownership of its own account. Without a copy, or when the object already links that copy, the link is removed. The listener is registered by event name, so an instance without Mail boots as before, and a failure is logged without stopping Mail's delete. Assisted-by: ClaudeCode:claude-opus-5-5
Mail drops the cached row of a moved message as well as a deleted one, and stores the moved copy only on its next sync, so the account reconcile removed the links of every mail moved to another folder or to the trash. - MailMessageDeletedListener becomes MailMessageLinksListener and also hears BeforeMessageDeletedEvent and NewMessagesSynchronized. A delete from the account's trash releases that one message: its links move to another stored copy or are removed. Any other event only repoints, so a moved mail's links wait for the copy and move to it once Mail stores it. - The listener runs at priority -1, after Mail's own cache listener, and is registered by IntegrationWiring next to the calendar link listeners, in the Integrations area with the reconciler. - The per-account queries move from EmailLinkMapper to EmailLinkAccountQueries, so the mapper keeps its public surface. Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
…mail relation too
Found on a live Nextcloud with Mail 5.13:
- NewMessagesSynchronized fires only on a partial sync, so a mailbox opened
for the first time never repointed its links. SynchronizationEvent fires
after every sync of the account and replaces it.
- Mail's MailAccount answers getTrashMailboxId() through __call, so the
method_exists() check never saw the trash and an expunge removed nothing.
The listener checks is_callable() instead.
- The Mail sidebar reads the object's `_mail` relation (`{account}/{message}`),
not the email link row. A repointed or removed link now moves or drops
that relation as well; a refused write (no user in a background sync) is
logged and the link still moves.
Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
Contributor
Quality Report — ConductionNL/openregister @
|
| Check | PHP | Vue | Security | License | Tests |
|---|---|---|---|---|---|
| lint | ❌ | ||||
| phpcs | ❌ | ||||
| phpmd | ❌ | ||||
| psalm | ❌ | ||||
| phpstan | ❌ | ||||
| phpmetrics | ❌ | ||||
| eslint | ❌ | ||||
| stylelint | ❌ | ||||
| build | ✅ | ||||
| check-specs | ❌ | ||||
| test-l10n | ❌ | ||||
| test-l10n-parity | ❌ | ||||
| test-l10n-browser-en | ✅ | ||||
| format | ❌ | ||||
| check-schema-l10n | ❌ | ||||
| test-newman-route-ratchet | ❌ | ||||
| composer | ❌ | ❌ | |||
| npm | ❌ | ✅ 671/671 | |||
| app:check-code | ⏭️ | ||||
| info.xml | ✅ | ||||
| REUSE | ✅ | ||||
| lockfile sync | ✅ | ||||
| PHPUnit | 🚨 NO VERDICT — enabled but never ran | ||||
| Newman | 🚨 NO VERDICT — enabled but never ran | ||||
| Playwright | 🚨 NO VERDICT — enabled but never ran | ||||
| Hydra gates | ⏭️ |
Quality workflow — 2026-12-02 12:51 UTC
Download the full PDF report from the workflow artifacts.
This branch has not been deployed
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.
What was wrong
What changes
_mail, which the sidebar's "Connected to" reads) moves and is removed together with the link. If that write is refused (no user during a background sync), it is logged and the link still moves.MailMessageLinksListenerhears Mail'sBeforeMessageDeletedEvent,MessageDeletedEventandSynchronizationEvent, after Mail's own listeners, and is registered with the other integration listeners. The per-account queries live in a newEmailLinkAccountQueries, soEmailLinkMapperkeeps its public surface. Both are mapped to the Integrations component.How it was tested
__callgetters such asgetTrashMailboxId()) and the wiring.PdfTextReplacerTestones (no PDF code touched).How it was tested on a live instance
Nextcloud 34.0.6 with Mail 5.13.5 and PostgreSQL 17, one user with two Mail accounts (1 and 2), an object whose schema allows mail links:
The live run found two problems the unit tests had missed, both fixed with a test: Mail fires no "new messages" event on a mailbox's first sync (the listener now uses
SynchronizationEvent), andgetTrashMailboxId()is a__callgetter, so amethod_existscheck never found the Trash.Notes
33e9185fcalone failsIntegrationRegistrarTest;ca96e33ecfixes it. Squash on merge if every commit has to be green.🤖 Generated with Claude Code