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/IMAP
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-04-16 17:24:06 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-04-16 18:03:35 +0300
commit8fafd264b27c960ab8323444bbb06b80c30d19b2 (patch)
tree66932dd5c7a5ec906eb270ece219fa6d494ef7df /lib/IMAP
parent823a25b41ccc382ec971ee40099932c88dbfc042 (diff)
Fix lower bound when fetching a range of IMAP messages for the sync
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/IMAP')
-rw-r--r--lib/IMAP/MessageMapper.php24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/IMAP/MessageMapper.php b/lib/IMAP/MessageMapper.php
index be8240410..7df82e9b9 100644
--- a/lib/IMAP/MessageMapper.php
+++ b/lib/IMAP/MessageMapper.php
@@ -71,18 +71,18 @@ class MessageMapper {
/**
* @param Horde_Imap_Client_Socket $client
- * @param Mailbox $mailbox
+ * @param string $mailbox
*
* @param int $maxResults
- * @param int|null $highestKnownUid
+ * @param int $highestKnownUid
*
* @return array
* @throws Horde_Imap_Client_Exception
*/
public function findAll(Horde_Imap_Client_Socket $client,
- Mailbox $mailbox,
+ string $mailbox,
int $maxResults,
- ?int $highestKnownUid = 0): array {
+ int $highestKnownUid): array {
/**
* To prevent memory exhaustion, we don't want to just ask for a list of
* all UIDs and limit them client-side. Instead we can (hopefully
@@ -94,7 +94,7 @@ class MessageMapper {
*/
$metaResults = $client->search(
- $mailbox->getName(),
+ $mailbox,
null,
[
'results' => [
@@ -125,11 +125,17 @@ class MessageMapper {
// +1 is added to fetch all messages with the rare case of strictly
// continuous UIDs and fractions
$estimatedPageSize = (int)(($totalRange / $total) * $maxResults) + 1;
+ // Determine min UID to fetch, but don't exceed the known maximum
+ $lower = max(
+ $min,
+ ($highestKnownUid ?? 0) + 1
+ );
// Determine max UID to fetch, but don't exceed the known maximum
$upper = min(
$max,
- $highestKnownUid + $estimatedPageSize
+ $lower + $estimatedPageSize
);
+ $this->logger->debug("Built range for findAll: min=$min max=$max total=$total totalRange=$totalRange estimatedPageSize=$estimatedPageSize lower=$lower upper=$upper highestKnownUid=$highestKnownUid");
$query = new Horde_Imap_Client_Fetch_Query();
$query->uid();
@@ -140,10 +146,10 @@ class MessageMapper {
return $data->getUid();
},
iterator_to_array($client->fetch(
- $mailbox->getName(),
+ $mailbox,
$query,
[
- 'ids' => new Horde_Imap_Client_Ids(($highestKnownUid + 1) . ':' . $upper)
+ 'ids' => new Horde_Imap_Client_Ids($lower . ':' . $upper)
]
))
),
@@ -159,7 +165,7 @@ class MessageMapper {
return [
'messages' => $this->findByIds(
$client,
- $mailbox->getName(),
+ $mailbox,
$uidsToFetch
),
'all' => $upper === $max,