Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2021-08-12 18:11:47 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-08-16 14:15:31 +0300
commit9617b2fbade244c3b70901b00fc8b91dc2e2cd5a (patch)
treec87a397a050145468d54a70e772748c9d6723b16 /lib
parent06edd02616adde377ea2488a8395ff4d8acdc9c4 (diff)
Ignore already known UIDs when looking for new ones
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/Service/Sync/ImapToDbSynchronizer.php16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/Service/Sync/ImapToDbSynchronizer.php b/lib/Service/Sync/ImapToDbSynchronizer.php
index b9a1467de..ea000c406 100644
--- a/lib/Service/Sync/ImapToDbSynchronizer.php
+++ b/lib/Service/Sync/ImapToDbSynchronizer.php
@@ -51,6 +51,7 @@ use OCP\EventDispatcher\IEventDispatcher;
use Psr\Log\LoggerInterface;
use Throwable;
use function array_chunk;
+use function array_filter;
use function array_map;
class ImapToDbSynchronizer {
@@ -354,7 +355,20 @@ class ImapToDbSynchronizer {
);
$perf->step('get new messages via Horde');
- foreach (array_chunk($response->getNewMessages(), 500) as $chunk) {
+ $highestKnownUid = $this->dbMapper->findHighestUid($mailbox);
+ if ($highestKnownUid === null) {
+ // Everything is relevant
+ $newMessages = $response->getNewMessages();
+ } else {
+ // Filter out anything that is already in the DB. Ideally this never happens, but if there is an error
+ // during a consecutive chunk INSERT, the sync token won't be updated. In that case the same message(s)
+ // will be seen as *new* and therefore cause conflicts.
+ $newMessages = array_filter($response->getNewMessages(), function (IMAPMessage $imapMessage) use ($highestKnownUid) {
+ return $imapMessage->getUid() > $highestKnownUid;
+ });
+ }
+
+ foreach (array_chunk($newMessages, 500) as $chunk) {
$dbMessages = array_map(function (IMAPMessage $imapMessage) use ($mailbox, $account) {
return $imapMessage->toDbMessage($mailbox->getId(), $account->getMailAccount());
}, $chunk);