Use UIDVALIDITY when HIGHESTMODSEQ not available, maybe solves #745

This commit is contained in:
the-djmaze 2022-12-05 11:09:42 +01:00
parent d48b3a74fc
commit f82574a472
3 changed files with 81 additions and 107 deletions

View file

@ -214,7 +214,7 @@ class Folder implements \JsonSerializable
'UidNext' => (int) $aStatus['UIDNEXT'], 'UidNext' => (int) $aStatus['UIDNEXT'],
// 'Hash' => $this->MailClient()->GenerateFolderHash( // 'Hash' => $this->MailClient()->GenerateFolderHash(
// $this->FullName(), $aStatus['MESSAGES'], $aStatus['UIDNEXT'], // $this->FullName(), $aStatus['MESSAGES'], $aStatus['UIDNEXT'],
// empty($aStatus['HIGHESTMODSEQ']) ? 0 : $aStatus['HIGHESTMODSEQ']) // empty($aStatus['HIGHESTMODSEQ']) ? $aStatus['UIDVALIDITY'] : $aStatus['HIGHESTMODSEQ'])
); );
} }
*/ */

View file

@ -417,7 +417,7 @@ class MailClient
\max(0, $oFolderStatus->UIDNEXT ?: 0), \max(0, $oFolderStatus->UIDNEXT ?: 0),
\max(0, $oFolderStatus->HIGHESTMODSEQ ?: 0), \max(0, $oFolderStatus->HIGHESTMODSEQ ?: $oFolderStatus->UIDVALIDITY),
$oFolderStatus->APPENDLIMIT ?: $this->oImapClient->AppendLimit(), $oFolderStatus->APPENDLIMIT ?: $this->oImapClient->AppendLimit(),
@ -820,53 +820,63 @@ class MailClient
$oInfo = $this->oImapClient->FolderStatusAndSelect($oParams->sFolderName); $oInfo = $this->oImapClient->FolderStatusAndSelect($oParams->sFolderName);
$oMessageCollection->FolderInfo = $oInfo; $oMessageCollection->FolderInfo = $oInfo;
$aUids = array();
$aAllThreads = []; $aAllThreads = [];
$bUseSortIfSupported = $oParams->bUseSortIfSupported && $this->oImapClient->IsSupported('SORT');
$bUseThreads = $oParams->bUseThreads ? $bUseThreads = $oParams->bUseThreads ?
($this->oImapClient->IsSupported('THREAD=REFS') || $this->oImapClient->IsSupported('THREAD=REFERENCES') || $this->oImapClient->IsSupported('THREAD=ORDEREDSUBJECT')) : false; ($this->oImapClient->IsSupported('THREAD=REFS') || $this->oImapClient->IsSupported('THREAD=REFERENCES') || $this->oImapClient->IsSupported('THREAD=ORDEREDSUBJECT')) : false;
if ($oParams->iThreadUid && !$bUseThreads) {
if ($oParams->iThreadUid && !$bUseThreads)
{
throw new \InvalidArgumentException('THREAD not supported'); throw new \InvalidArgumentException('THREAD not supported');
} }
if (!$oParams->oCacher || !($oParams->oCacher instanceof \MailSo\Cache\CacheClient)) if (!$oParams->oCacher || !($oParams->oCacher instanceof \MailSo\Cache\CacheClient)) {
{
$oParams->oCacher = null; $oParams->oCacher = null;
} }
$oMessageCollection->FolderHash = $this->GenerateFolderHash( $oMessageCollection->FolderHash = $this->GenerateFolderHash(
$oParams->sFolderName, $oInfo->MESSAGES, $oInfo->UIDNEXT, $oInfo->HIGHESTMODSEQ $oParams->sFolderName, $oInfo->MESSAGES, $oInfo->UIDNEXT, $oInfo->HIGHESTMODSEQ ?: $oInfo->UIDVALIDITY
); );
if (!$oParams->iThreadUid) if (!$oParams->iThreadUid) {
{
$oMessageCollection->NewMessages = $this->getFolderNextMessageInformation( $oMessageCollection->NewMessages = $this->getFolderNextMessageInformation(
$oParams->sFolderName, $oParams->iPrevUidNext, $oInfo->UIDNEXT $oParams->sFolderName, $oParams->iPrevUidNext, $oInfo->UIDNEXT
); );
} }
$bSearch = false; if ($oInfo->MESSAGES) {
$bMessageListOptimization = 0 < \MailSo\Config::$MessageListCountLimitTrigger && if (0 < \MailSo\Config::$MessageListCountLimitTrigger && \MailSo\Config::$MessageListCountLimitTrigger < $oInfo->MESSAGES) {
\MailSo\Config::$MessageListCountLimitTrigger < $oInfo->MESSAGES; if ($this->oLogger) {
$this->oLogger->Write('List optimization (count: '.$oInfo->MESSAGES.
if ($bMessageListOptimization) ', limit:'.\MailSo\Config::$MessageListCountLimitTrigger.')');
{
$bUseSortIfSupported = false;
$bUseThreads = false;
} }
if (\strlen($sSearch)) {
$aUids = $this->GetUids($oParams, $sSearch,
$oMessageCollection->FolderName, $oMessageCollection->FolderHash);
if ($oInfo->MESSAGES && !$bMessageListOptimization) $oMessageCollection->MessageResultCount = \count($aUids);
{ if ($oMessageCollection->MessageResultCount) {
$this->MessageListByRequestIndexOrUids(
$oMessageCollection,
new SequenceSet(\array_slice($aUids, $oParams->iOffset, $oParams->iLimit))
);
}
} else {
$oMessageCollection->MessageResultCount = $oInfo->MESSAGES;
if (1 < $oInfo->MESSAGES) {
$end = \max(1, $oInfo->MESSAGES - $oParams->iOffset);
$start = \max(1, $end - $oParams->iLimit + 1);
$aRequestIndexes = \range($start, $end);
} else {
$aRequestIndexes = \array_slice([1], $oParams->iOffset, 1);
}
$this->MessageListByRequestIndexOrUids($oMessageCollection, new SequenceSet($aRequestIndexes, false));
}
} else {
$aUids = [];
$bUseSortIfSupported = $oParams->bUseSortIfSupported && $this->oImapClient->IsSupported('SORT');
if ($bUseThreads) { if ($bUseThreads) {
$aAllThreads = $this->MessageListThreadsMap($oMessageCollection->FolderName, $oMessageCollection->FolderHash, $oParams->oCacher); $aAllThreads = $this->MessageListThreadsMap($oMessageCollection->FolderName, $oMessageCollection->FolderHash, $oParams->oCacher);
// $iThreadLimit = \MailSo\Config::$LargeThreadLimit; // $iThreadLimit = \MailSo\Config::$LargeThreadLimit;
if ($oParams->iThreadUid) {
if ($oParams->iThreadUid)
{
$aUids = [$oParams->iThreadUid]; $aUids = [$oParams->iThreadUid];
// Only show the selected thread messages // Only show the selected thread messages
foreach ($aAllThreads as $aMap) { foreach ($aAllThreads as $aMap) {
@ -875,9 +885,7 @@ class MailClient
break; break;
} }
} }
} } else {
else
{
$aUids = $this->GetUids($oParams, '', $aUids = $this->GetUids($oParams, '',
$oMessageCollection->FolderName, $oMessageCollection->FolderHash, $bUseSortIfSupported, $oParams->sSort); $oMessageCollection->FolderName, $oMessageCollection->FolderHash, $bUseSortIfSupported, $oParams->sSort);
// Remove all threaded UID's except the most recent of each thread // Remove all threaded UID's except the most recent of each thread
@ -893,8 +901,7 @@ class MailClient
$oMessageCollection->FolderName, $oMessageCollection->FolderHash, $bUseSortIfSupported, $oParams->sSort); $oMessageCollection->FolderName, $oMessageCollection->FolderHash, $bUseSortIfSupported, $oParams->sSort);
} }
if ($aUids && \strlen($sSearch)) if ($aUids && \strlen($sSearch)) {
{
$aSearchedUids = $this->GetUids($oParams, $sSearch, $aSearchedUids = $this->GetUids($oParams, $sSearch,
$oMessageCollection->FolderName, $oMessageCollection->FolderHash); $oMessageCollection->FolderName, $oMessageCollection->FolderHash);
if ($bUseThreads && !$oParams->iThreadUid) { if ($bUseThreads && !$oParams->iThreadUid) {
@ -916,51 +923,18 @@ class MailClient
$oMessageCollection->MessageResultCount = \count($aUids); $oMessageCollection->MessageResultCount = \count($aUids);
if (\count($aUids)) if (\count($aUids)) {
{
$this->MessageListByRequestIndexOrUids( $this->MessageListByRequestIndexOrUids(
$oMessageCollection, $oMessageCollection,
new SequenceSet(\array_slice($aUids, $oParams->iOffset, $oParams->iLimit)) new SequenceSet(\array_slice($aUids, $oParams->iOffset, $oParams->iLimit))
); );
} }
} }
else if ($oInfo->MESSAGES) } else if ($this->oLogger) {
{ $this->oLogger->Write('No messages in '.$oMessageCollection->FolderName);
if ($this->oLogger)
{
$this->oLogger->Write('List optimization (count: '.$oInfo->MESSAGES.
', limit:'.\MailSo\Config::$MessageListCountLimitTrigger.')');
} }
if (\strlen($sSearch)) if ($aAllThreads && !$oParams->iThreadUid) {
{
$aUids = $this->GetUids($oParams, $sSearch,
$oMessageCollection->FolderName, $oMessageCollection->FolderHash);
$oMessageCollection->MessageResultCount = \count($aUids);
if ($oMessageCollection->MessageResultCount) {
$this->MessageListByRequestIndexOrUids(
$oMessageCollection,
new SequenceSet(\array_slice($aUids, $oParams->iOffset, $oParams->iLimit))
);
}
}
else
{
$oMessageCollection->MessageResultCount = $oInfo->MESSAGES;
if (1 < $oInfo->MESSAGES) {
$end = \max(1, $oInfo->MESSAGES - $oParams->iOffset);
$start = \max(1, $end - $oParams->iLimit + 1);
$aRequestIndexes = \range($start, $end);
} else {
$aRequestIndexes = \array_slice([1], $oParams->iOffset, 1);
}
$this->MessageListByRequestIndexOrUids($oMessageCollection, new SequenceSet($aRequestIndexes, false));
}
}
if ($aAllThreads && !$oParams->iThreadUid)
{
foreach ($oMessageCollection as $oMessage) { foreach ($oMessageCollection as $oMessage) {
$iUid = $oMessage->Uid(); $iUid = $oMessage->Uid();
// Find thread and set it. // Find thread and set it.

View file

@ -256,7 +256,7 @@ trait Response
$mResponse->FullName(), $mResponse->FullName(),
$aStatus['MESSAGES'], $aStatus['MESSAGES'],
$aStatus['UIDNEXT'], $aStatus['UIDNEXT'],
empty($aStatus['HIGHESTMODSEQ']) ? 0 : $aStatus['HIGHESTMODSEQ'] empty($aStatus['HIGHESTMODSEQ']) ? $aStatus['UIDVALIDITY'] : $aStatus['HIGHESTMODSEQ']
); );
} }