Idea to fetch all UID's in background

This commit is contained in:
the-djmaze 2023-11-27 14:36:46 +01:00
parent 612aa09071
commit 771c6f7559
3 changed files with 147 additions and 92 deletions

View file

@ -673,20 +673,32 @@ class MailClient
throw new \InvalidArgumentException('THREAD not supported'); throw new \InvalidArgumentException('THREAD not supported');
} }
if (!$oInfo->MESSAGES) {
$this->logWrite('No messages in '.$oMessageCollection->FolderName);
return $oMessageCollection;
}
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
); );
} }
if ($oInfo->MESSAGES) {
$bUseSort = $oParams->bUseSort || $oParams->sSort; $bUseSort = $oParams->bUseSort || $oParams->sSort;
$aAllThreads = []; $aAllThreads = [];
$aUnseenUIDs = []; $aUnseenUIDs = [];
$aUids = []; $aUids = [];
$message_list_limit = $this->oImapClient->Settings->message_list_limit; $message_list_limit = $oParams->bIgnoreLimit ? 0 : $this->oImapClient->Settings->message_list_limit;
if (0 < $message_list_limit && $message_list_limit < $oInfo->MESSAGES) { if (0 < $message_list_limit && $message_list_limit < $oInfo->MESSAGES) {
/*
// TODO: Idea to fetch all UID's in background
// Must know what is cached so needs more thought
\SnappyMail\Shutdown::add(function($oMailClient, $oParams) {
$oParams->bIgnoreLimit = true;
$oMailClient->MessageList($oParams);
}, [$this, $oParams]);
*/
// if ((0 < $message_list_limit && $message_list_limit < $oInfo->MESSAGES) // if ((0 < $message_list_limit && $message_list_limit < $oInfo->MESSAGES)
// || (!$this->oImapClient->hasCapability('SORT') && !$this->oImapClient->CapabilityValue('THREAD'))) { // || (!$this->oImapClient->hasCapability('SORT') && !$this->oImapClient->CapabilityValue('THREAD'))) {
// Don't use THREAD for speed // Don't use THREAD for speed
@ -773,9 +785,6 @@ class MailClient
$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);
} }
} else {
$this->logWrite('No messages in '.$oMessageCollection->FolderName);
}
return $oMessageCollection; return $oMessageCollection;
} }

View file

@ -24,7 +24,8 @@ class MessageListParams
public bool public bool
$bUseSort = true, $bUseSort = true,
$bUseThreads = false, $bUseThreads = false,
$bHideDeleted = true; $bHideDeleted = true,
$bIgnoreLimit = false;
protected int protected int
$iOffset = 0, $iOffset = 0,

View file

@ -0,0 +1,45 @@
<?php
namespace SnappyMail;
abstract class Shutdown
{
private static
$actions = [],
$running = false;
final public function run() : void
{
if (!static::$running && \count(static::$actions)) {
static::$running = true;
\ini_set('display_errors', 0);
\ignore_user_abort(true);
# Flush all output buffers
if ($i = \ob_get_level()) {
while ($i-- && \ob_end_flush());
}
\flush();
if (\is_callable('fastcgi_finish_request')) {
// Special FPM/FastCGI (fpm-fcgi) function to finish request and
// flush all data while continuing to do something time-consuming.
\fastcgi_finish_request();
}
foreach (static::$actions as $action) {
try {
\call_user_func_array($action[0], $action[1]);
} catch (\Throwable $e) { } # skip
}
}
}
final public function add(callable $function, array $args = []) : void
{
if (!\count(static::$actions)) {
\register_shutdown_function('\\SnappyMail\\Shutdown::run');
}
static::$actions[] = [$function, $args];
}
}