This commit is contained in:
the-djmaze 2024-09-21 00:28:13 +02:00
parent a4299c5f1c
commit 56db74986f

View file

@ -553,12 +553,14 @@ class MailClient
$aSortUids = \array_reduce($aAllThreads, 'array_merge', []); $aSortUids = \array_reduce($aAllThreads, 'array_merge', []);
$oParams->oSequenceSet = new \MailSo\Imap\SequenceSet($aSortUids); $oParams->oSequenceSet = new \MailSo\Imap\SequenceSet($aSortUids);
$aSortUids = $this->GetUids($oParams, $oFolderInfo); $aSortUids = $this->GetUids($oParams, $oFolderInfo);
if ($aSortUids) {
foreach ($aAllThreads as $aThreadUIDs) { foreach ($aAllThreads as $aThreadUIDs) {
$aThreadUIDs = \array_intersect($aSortUids, $aThreadUIDs); $aThreadUIDs = \array_intersect($aSortUids, $aThreadUIDs);
// Remove the most recent UID // Remove the most recent UID
\array_pop($aThreadUIDs); \array_pop($aThreadUIDs);
$aUids = \array_merge($aUids, $aThreadUIDs); $aUids = \array_merge($aUids, $aThreadUIDs);
} }
}
*/ */
} else { } else {
// Not the best solution to remove the most recent UID, // Not the best solution to remove the most recent UID,
@ -631,7 +633,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
private function GetUids(MessageListParams $oParams, FolderInformation $oInfo, bool $onlyCache = false) : array private function GetUids(MessageListParams $oParams, FolderInformation $oInfo, bool $onlyCache = false) : ?array
{ {
$oCacher = $oParams->oCacher; $oCacher = $oParams->oCacher;
$sFolderName = $oParams->sFolderName; $sFolderName = $oParams->sFolderName;
@ -691,7 +693,7 @@ class MailClient
} }
} }
if ($onlyCache) { if ($onlyCache) {
return []; return null;
} }
$this->oImapClient->FolderExamine($sFolderName); $this->oImapClient->FolderExamine($sFolderName);
@ -794,7 +796,7 @@ class MailClient
$aAllThreads = []; $aAllThreads = [];
$aUnseenUIDs = []; $aUnseenUIDs = [];
$aUids = []; $aUids = null;
$message_list_limit = $this->oImapClient->Settings->message_list_limit; $message_list_limit = $this->oImapClient->Settings->message_list_limit;
if (100 > $message_list_limit || $message_list_limit > $oInfo->MESSAGES) { if (100 > $message_list_limit || $message_list_limit > $oInfo->MESSAGES) {
@ -807,7 +809,7 @@ class MailClient
$oAllParams->oSequenceSet = null; $oAllParams->oSequenceSet = null;
if ($message_list_limit && !$oParams->iThreadUid && $oParams->oCacher && $oParams->oCacher->IsInited()) { if ($message_list_limit && !$oParams->iThreadUid && $oParams->oCacher && $oParams->oCacher->IsInited()) {
$aUids = $this->GetUids($oAllParams, $oInfo, true); $aUids = $this->GetUids($oAllParams, $oInfo, true);
if ($aUids) { if (null !== $aUids) {
$message_list_limit = 0; $message_list_limit = 0;
$oMessageCollection->Sort = $oAllParams->sSort; $oMessageCollection->Sort = $oAllParams->sSort;
} else { } else {
@ -898,11 +900,13 @@ class MailClient
} }
} }
if (\is_array($aUids)) {
$oMessageCollection->totalEmails = \count($aUids); $oMessageCollection->totalEmails = \count($aUids);
if ($oMessageCollection->totalEmails) { if ($oMessageCollection->totalEmails) {
$aUids = \array_slice($aUids, $oParams->iOffset, $oParams->iLimit); $aUids = \array_slice($aUids, $oParams->iOffset, $oParams->iLimit);
$this->MessageListByRequestIndexOrUids($oMessageCollection, new SequenceSet($aUids), $aAllThreads, $aUnseenUIDs); $this->MessageListByRequestIndexOrUids($oMessageCollection, new SequenceSet($aUids), $aAllThreads, $aUnseenUIDs);
} }
}
return $oMessageCollection; return $oMessageCollection;
} }