mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-14 00:54:18 +08:00
MailSo message count optimizations
This commit is contained in:
parent
5aea463333
commit
d8dc6ee5ec
4 changed files with 76 additions and 28 deletions
|
@ -647,10 +647,11 @@ class MailClient
|
|||
* @param int $iCount
|
||||
* @param int $iUnseenCount
|
||||
* @param string $sUidNext
|
||||
* @param \MailSo\Cache\CacheClient|null $oCacher = null
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initFolderValues($sFolderName, &$iCount, &$iUnseenCount, &$sUidNext)
|
||||
protected function initFolderValues($sFolderName, &$iCount, &$iUnseenCount, &$sUidNext, $oCacher = null)
|
||||
{
|
||||
$aFolderStatus = $this->oImapClient->FolderStatus($sFolderName, array(
|
||||
\MailSo\Imap\Enumerations\FolderResponseStatus::MESSAGES,
|
||||
|
@ -667,7 +668,30 @@ class MailClient
|
|||
$sUidNext = isset($aFolderStatus[\MailSo\Imap\Enumerations\FolderResponseStatus::UIDNEXT])
|
||||
? (string) $aFolderStatus[\MailSo\Imap\Enumerations\FolderResponseStatus::UIDNEXT] : '0';
|
||||
|
||||
if ($this->IsGmail())
|
||||
if (\MailSo\Config::$MessageListUndeletedFilter)
|
||||
{
|
||||
$aUids = $this->getSearchUidsResult('',
|
||||
$sFolderName, false, false, false, $oCacher);
|
||||
|
||||
$iNewCount = \count($aUids);
|
||||
if (0 < $iNewCount && $iNewCount !== $iCount)
|
||||
{
|
||||
$iCount = $iNewCount;
|
||||
|
||||
$aUids = $this->getSearchUidsResult('is:unread',
|
||||
$sFolderName, false, false, false, $oCacher);
|
||||
|
||||
$iUnseenCount = \count($aUids);
|
||||
}
|
||||
else
|
||||
{
|
||||
$iCount = 0;
|
||||
$iUnseenCount = 0;
|
||||
}
|
||||
|
||||
unset($aUids);
|
||||
}
|
||||
else if ($this->IsGmail())
|
||||
{
|
||||
$oFolder = $this->oImapClient->FolderCurrentInformation();
|
||||
if ($oFolder && null !== $oFolder->Exists && $oFolder->FolderName === $sFolderName)
|
||||
|
@ -770,6 +794,7 @@ class MailClient
|
|||
* @param string $sFolderName
|
||||
* @param string $sPrevUidNext = ''
|
||||
* @param array $aUids = ''
|
||||
* @param \MailSo\Cache\CacheClient|null $oCacher = null
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
|
@ -777,7 +802,7 @@ class MailClient
|
|||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Imap\Exceptions\Exception
|
||||
*/
|
||||
public function FolderInformation($sFolderName, $sPrevUidNext = '', $aUids = array())
|
||||
public function FolderInformation($sFolderName, $sPrevUidNext = '', $aUids = array(), $oCacher = null)
|
||||
{
|
||||
$aFlags = array();
|
||||
|
||||
|
@ -816,7 +841,7 @@ class MailClient
|
|||
$iUnseenCount = 0;
|
||||
$sUidNext = '0';
|
||||
|
||||
$this->initFolderValues($sFolderName, $iCount, $iUnseenCount, $sUidNext);
|
||||
$this->initFolderValues($sFolderName, $iCount, $iUnseenCount, $sUidNext, $oCacher);
|
||||
|
||||
$aResult = array(
|
||||
'Folder' => $sFolderName,
|
||||
|
@ -834,6 +859,7 @@ class MailClient
|
|||
|
||||
/**
|
||||
* @param string $sFolderName
|
||||
* @param \MailSo\Cache\CacheClient|null $oCacher = null
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
|
@ -841,13 +867,13 @@ class MailClient
|
|||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Imap\Exceptions\Exception
|
||||
*/
|
||||
public function FolderHash($sFolderName)
|
||||
public function FolderHash($sFolderName, $oCacher = null)
|
||||
{
|
||||
$iCount = 0;
|
||||
$iUnseenCount = 0;
|
||||
$sUidNext = '0';
|
||||
|
||||
$this->initFolderValues($sFolderName, $iCount, $iUnseenCount, $sUidNext);
|
||||
$this->initFolderValues($sFolderName, $iCount, $iUnseenCount, $sUidNext, $oCacher);
|
||||
|
||||
return self::GenerateHash($sFolderName, $iCount, $iUnseenCount, $sUidNext);
|
||||
}
|
||||
|
@ -1538,7 +1564,7 @@ class MailClient
|
|||
/**
|
||||
* @param string $sSearch
|
||||
* @param string $sFolderName
|
||||
* @param string $sFolderHash
|
||||
* @param string|bool $sFolderHash
|
||||
* @param bool $bUseSortIfSupported = true
|
||||
* @param bool $bUseESearchOrESortRequest = false
|
||||
* @param \MailSo\Cache\CacheClient|null $oCacher = null
|
||||
|
@ -1576,7 +1602,7 @@ class MailClient
|
|||
$aSerialized = @\unserialize($sSerialized);
|
||||
if (\is_array($aSerialized) && isset($aSerialized['FolderHash'], $aSerialized['Uids']) &&
|
||||
\is_array($aSerialized['Uids']) &&
|
||||
$sFolderHash === $aSerialized['FolderHash'])
|
||||
($sFolderHash === $aSerialized['FolderHash'] || false === $sFolderHash))
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
|
@ -1730,7 +1756,7 @@ class MailClient
|
|||
$oCacher = null;
|
||||
}
|
||||
|
||||
$this->initFolderValues($sFolderName, $iMessageRealCount, $iMessageUnseenCount, $sUidNext);
|
||||
$this->initFolderValues($sFolderName, $iMessageRealCount, $iMessageUnseenCount, $sUidNext, $oCacher);
|
||||
$iMessageCount = $iMessageRealCount;
|
||||
|
||||
$oMessageCollection->FolderHash = self::GenerateHash($sFolderName, $iMessageRealCount, $iMessageUnseenCount, $sUidNext);
|
||||
|
|
|
@ -4123,7 +4123,9 @@ class Actions
|
|||
$sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', '');
|
||||
try
|
||||
{
|
||||
$aInboxInformation = $this->MailClient()->FolderInformation($sFolder, $sPrevUidNext, $aFlagsFilteredUids);
|
||||
$aInboxInformation = $this->MailClient()->FolderInformation(
|
||||
$sFolder, $sPrevUidNext, $aFlagsFilteredUids, $this->cacherForUids()
|
||||
);
|
||||
if (\is_array($aInboxInformation) && isset($aInboxInformation['Flags']) && \is_array($aInboxInformation['Flags']))
|
||||
{
|
||||
foreach ($aInboxInformation['Flags'] as $iUid => $aFlags)
|
||||
|
@ -4176,7 +4178,10 @@ class Actions
|
|||
{
|
||||
try
|
||||
{
|
||||
$aInboxInformation = $this->MailClient()->FolderInformation($sFolder);
|
||||
$aInboxInformation = $this->MailClient()->FolderInformation(
|
||||
$sFolder, '', array(), $this->cacherForUids()
|
||||
);
|
||||
|
||||
if (\is_array($aInboxInformation) && isset($aInboxInformation['Folder']))
|
||||
{
|
||||
$aResult['List'][] = $aInboxInformation;
|
||||
|
@ -4269,7 +4274,7 @@ class Actions
|
|||
|
||||
$oMessageList = $this->MailClient()->MessageList(
|
||||
$sFolder, $iOffset, $iLimit, $sSearch, $sUidNext,
|
||||
($this->Config()->Get('cache', 'enable', true) && $this->Config()->Get('cache', 'server_uids', false)) ? $this->Cacher() : null,
|
||||
$this->cacherForUids(),
|
||||
!!$this->Config()->Get('labs', 'use_imap_sort', false),
|
||||
$bUseThreads, $aExpandedThreadUid,
|
||||
!!$this->Config()->Get('labs', 'use_imap_esearch_esort', false)
|
||||
|
@ -5577,7 +5582,7 @@ class Actions
|
|||
try
|
||||
{
|
||||
$oMessage = $this->MailClient()->Message($sFolder, $iUid, true,
|
||||
!!$this->Config()->Get('labs', 'use_imap_thread', false) ? $this->Cacher() : null,
|
||||
$this->cacherForThreads(),
|
||||
(int) $this->Config()->Get('labs', 'imap_body_text_limit', 0)
|
||||
);
|
||||
}
|
||||
|
@ -5609,17 +5614,18 @@ class Actions
|
|||
$this->initMailClientConnection();
|
||||
|
||||
$sFolder = $this->GetActionParam('Folder', '');
|
||||
$aUids = explode(',', (string) $this->GetActionParam('Uids', ''));
|
||||
$aUids = \explode(',', (string) $this->GetActionParam('Uids', ''));
|
||||
|
||||
$aFilteredUids = array_filter($aUids, function (&$sUid) {
|
||||
$sUid = (int) trim($sUid);
|
||||
$aFilteredUids = \array_filter($aUids, function (&$sUid) {
|
||||
$sUid = (int) \trim($sUid);
|
||||
return 0 < $sUid;
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
$this->MailClient()->MessageDelete($sFolder, $aFilteredUids, true);
|
||||
$sHash = $this->MailClient()->FolderHash($sFolder);
|
||||
|
||||
$sHash = $this->MailClient()->FolderHash($sFolder, $this->cacherForUids());
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
|
@ -5640,10 +5646,10 @@ class Actions
|
|||
|
||||
$sFromFolder = $this->GetActionParam('FromFolder', '');
|
||||
$sToFolder = $this->GetActionParam('ToFolder', '');
|
||||
$aUids = explode(',', (string) $this->GetActionParam('Uids', ''));
|
||||
$aUids = \explode(',', (string) $this->GetActionParam('Uids', ''));
|
||||
|
||||
$aFilteredUids = array_filter($aUids, function (&$mUid) {
|
||||
$mUid = (int) trim($mUid);
|
||||
$aFilteredUids = \array_filter($aUids, function (&$mUid) {
|
||||
$mUid = (int) \trim($mUid);
|
||||
return 0 < $mUid;
|
||||
});
|
||||
|
||||
|
@ -5652,7 +5658,7 @@ class Actions
|
|||
$this->MailClient()->MessageMove($sFromFolder, $sToFolder,
|
||||
$aFilteredUids, true, $this->Config()->Get('labs', 'use_imap_move', true));
|
||||
|
||||
$sHash = $this->MailClient()->FolderHash($sFromFolder);
|
||||
$sHash = $this->MailClient()->FolderHash($sFromFolder, $this->cacherForUids());
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
|
@ -5674,10 +5680,10 @@ class Actions
|
|||
|
||||
$sFromFolder = $this->GetActionParam('FromFolder', '');
|
||||
$sToFolder = $this->GetActionParam('ToFolder', '');
|
||||
$aUids = explode(',', (string) $this->GetActionParam('Uids', ''));
|
||||
$aUids = \explode(',', (string) $this->GetActionParam('Uids', ''));
|
||||
|
||||
$aFilteredUids = array_filter($aUids, function (&$mUid) {
|
||||
$mUid = (int) trim($mUid);
|
||||
$aFilteredUids = \array_filter($aUids, function (&$mUid) {
|
||||
$mUid = (int) \trim($mUid);
|
||||
return 0 < $mUid;
|
||||
});
|
||||
|
||||
|
@ -5686,7 +5692,7 @@ class Actions
|
|||
$this->MailClient()->MessageCopy($sFromFolder, $sToFolder,
|
||||
$aFilteredUids, true);
|
||||
|
||||
$sHash = $this->MailClient()->FolderHash($sFromFolder);
|
||||
$sHash = $this->MailClient()->FolderHash($sFromFolder, $this->cacherForUids());
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
|
@ -7192,6 +7198,22 @@ class Actions
|
|||
|
||||
return isset($aLang[$sKey]) ? $aLang[$sKey] : $sKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MailSo\Cache\CacheClient|null
|
||||
*/
|
||||
private function cacherForUids()
|
||||
{
|
||||
return ($this->Config()->Get('cache', 'enable', true) && $this->Config()->Get('cache', 'server_uids', false)) ? $this->Cacher() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MailSo\Cache\CacheClient|null
|
||||
*/
|
||||
private function cacherForThreads()
|
||||
{
|
||||
return !!$this->Config()->Get('labs', 'use_imap_thread', false) ? $this->Cacher() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSubject
|
||||
|
|
|
@ -86,7 +86,7 @@ class Api
|
|||
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_date_filter', 0);
|
||||
|
||||
\MailSo\Config::$MessageListUndeletedFilter =
|
||||
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_list_hide_deleted_messages', true);
|
||||
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_list_hide_deleted_messages', false);
|
||||
|
||||
\MailSo\Config::$SystemLogger = \RainLoop\Api::Logger();
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ Enables caching in the system'),
|
|||
'use_app_debug_js' => array(false),
|
||||
'use_app_debug_css' => array(false),
|
||||
'use_imap_sort' => array(true),
|
||||
'use_imap_esearch_esort' => array(false),
|
||||
'use_imap_esearch_esort' => array(true),
|
||||
'use_imap_force_selection' => array(false),
|
||||
'use_imap_list_subscribe' => array(true),
|
||||
'use_imap_thread' => array(true),
|
||||
|
@ -242,7 +242,7 @@ Enables caching in the system'),
|
|||
'imap_read_receipt_flag' => array('$ReadReceipt'),
|
||||
'imap_body_text_limit' => array(555000),
|
||||
'imap_message_list_fast_simple_search' => array(true),
|
||||
'imap_message_list_hide_deleted_messages' => array(true),
|
||||
'imap_message_list_hide_deleted_messages' => array(false),
|
||||
'imap_message_list_count_limit_trigger' => array(0),
|
||||
'imap_message_list_date_filter' => array(0),
|
||||
'smtp_show_server_errors' => array(false),
|
||||
|
|
Loading…
Add table
Reference in a new issue