Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sync): mailboxes not being synced due to short circuiting #8575

Merged
merged 1 commit into from
Jul 3, 2023

Conversation

st3iny
Copy link
Member

@st3iny st3iny commented Jun 26, 2023

Fix #8223

If a mailbox causes threads to be rebuilt during background sync, all succeeding mailboxes will be skipped due to a short circuit evaluation of the logical or operator.

Consider this piece of code: https://3v4l.org/kK4Dc

@meichthys
Copy link

I'm not sure if it's entirely relevant, but I only have a single account and i'm still seeing the error despite patching in these changes.

@st3iny
Copy link
Member Author

st3iny commented Jun 29, 2023

You might need to resync your account by removing it and adding it again. This fix will only prevent the issue from happening in the future. It does not necessarily fix all emails that are already missing.

@ChristophWurst
Copy link
Member

If we reset sync tokens, would we able to fix historically incorrect data?

@meichthys
Copy link

meichthys commented Jun 29, 2023

@st3iny Even after removing my account and re-adding it I'm still seeing the same issue for old and new emails.
Do i need to remove the mail app and all it's data somehow before re-configuring the account?
image

@st3iny
Copy link
Member Author

st3iny commented Jun 29, 2023

@meichthys That is bad. Are you sure that you patched the mail app and didn't update it since? Updating will overwrite the patch.

Adding the account again should be sufficient.

@meichthys
Copy link

meichthys commented Jun 29, 2023

@st3iny Yes, here is the content of my ImapToDbSynchronizer.php:

        public function syncAccount(Account $account,
                                                                LoggerInterface $logger,
                                                                bool $force = false,
                                                                int $criteria = Horde_Imap_Client::SYNC>
                $rebuildThreads = false;
                foreach ($this->mailboxMapper->findAll($account) as $mailbox) {
                        if (!$mailbox->isInbox() && !$mailbox->getSyncInBackground()) {
                                $logger->debug("Skipping mailbox sync for " . $mailbox->getId());
                                continue;
                        }
                        $logger->debug("Syncing " . $mailbox->getId());
                        if ($this->sync(
                                        $account,
                                        $mailbox,
                                        $logger,
                                        $criteria,
                                        null,
                                        $force,
                                        true
                        )) {
                                $rebuildThreads = true;
                        }
                }
                $this->dispatcher->dispatchTyped(
                        new SynchronizationEvent(
                                $account,
                                $logger,
                                $rebuildThreads,
                        )
                );
        }

There is however, another ImapToDbSynchronizer.php.save file in the same directory, but i'm assuming that does not get loaded since it is named with the .save suffix.

@st3iny
Copy link
Member Author

st3iny commented Jul 3, 2023

So I've been testing this PR at my personal instance for about a week now and it fixes the issue for me. I think we should move on with this PR.


If we reset sync tokens, would we able to fix historically incorrect data?

Hmm, that will trigger a potential costly initial sync. It should fix the issue though. Alternatively, it would also be sufficient to trigger a vanished sync without QRESYNC once, which will just send all UIDs to the server and correctly detect vanished UIDs. That would require some extra code.

private function getVanishedMessageUids(Horde_Imap_Client_Base $imapClient, Horde_Imap_Client_Mailbox $mailbox, Request $request): array {
if ($imapClient->capability->isEnabled('QRESYNC')) {
return $imapClient->sync($mailbox, $request->getToken(), [
'criteria' => Horde_Imap_Client::SYNC_VANISHEDUIDS,
])->vanisheduids->ids;
}

@st3iny st3iny marked this pull request as ready for review July 3, 2023 09:00
@st3iny st3iny added this to the v3.3.0 milestone Jul 3, 2023
@st3iny
Copy link
Member Author

st3iny commented Jul 3, 2023

/backport to stable3.2

@st3iny
Copy link
Member Author

st3iny commented Jul 3, 2023

/backport to stable2.2

@st3iny st3iny force-pushed the fix/rebuild-threads-short-circuit branch from ae8d245 to 7c2c806 Compare July 3, 2023 09:04
@st3iny
Copy link
Member Author

st3iny commented Jul 3, 2023

Static analysis errors are unrelated.

@ChristophWurst
Copy link
Member

Let's get this in to have new accounts sync properly and tackle historically incorrect data separately.

Alternatively, it would also be sufficient to trigger a vanished sync without QRESYNC once, which will just send all UIDs to the server and correctly detect vanished UIDs. That would require some extra code.

We'll probably have to do this with our own logic because Horde uses QRESYNC if supported. We can fetch all known UIDs in chunks and delete the ones that are not returned. That sounds doable 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Old mails deleted on other clients still show up as unread in Mail, when opened "Not found"
3 participants