mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
Optimizations
Added "[labs]imap_folder_list_limit" setting (optimization)
This commit is contained in:
parent
833f40c115
commit
7ef9ebb45f
22 changed files with 878 additions and 32 deletions
|
|
@ -608,7 +608,8 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
|
||||
/**
|
||||
* @param array $aResult
|
||||
* @param bool $bIsSubscribeList
|
||||
* @param string $sStatus
|
||||
* @param bool $bUseListStatus = false
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -196,6 +196,14 @@ class Attachment
|
|||
return $this->oBodyStructure ? $this->oBodyStructure->IsDoc() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsPgpSignature()
|
||||
{
|
||||
return $this->oBodyStructure ? $this->oBodyStructure->IsPgpSignature() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \MailSo\Mail\Attachment
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -104,4 +104,16 @@ class AttachmentCollection extends \MailSo\Base\Collection
|
|||
|
||||
return \is_array($aList) ? \count($aList) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function CertificateCount()
|
||||
{
|
||||
$aList = $this->FilterList(function ($oAttachment) {
|
||||
return $oAttachment && $oAttachment->IsPgpSignature();
|
||||
});
|
||||
|
||||
return \is_array($aList) ? \count($aList) : 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ class FolderCollection extends \MailSo\Base\Collection
|
|||
*/
|
||||
public $IsThreadsSupported;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $Optimized;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
|
@ -48,6 +53,7 @@ class FolderCollection extends \MailSo\Base\Collection
|
|||
$this->FoldersHash = '';
|
||||
$this->SystemFolders = array();
|
||||
$this->IsThreadsSupported = false;
|
||||
$this->Optimized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1914,7 +1914,8 @@ class MailClient
|
|||
|
||||
if (1 < $iMessageCount)
|
||||
{
|
||||
if ($bMessageListOptimization || 0 === \MailSo\Config::$MessageListDateFilter)
|
||||
if (0 === \MailSo\Config::$MessageListDateFilter &&
|
||||
($bMessageListOptimization || !$bUseSortIfSupported))
|
||||
{
|
||||
$aIndexOrUids = \array_reverse(\range(1, $iMessageCount));
|
||||
}
|
||||
|
|
@ -2013,19 +2014,140 @@ class MailClient
|
|||
return \is_array($aUids) && 1 === \count($aUids) && \is_numeric($aUids[0]) ? (int) $aUids[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aMailFoldersHelper
|
||||
* @param int $iOptimizationLimit = 0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function folerListOptimization($aMailFoldersHelper, $iOptimizationLimit = 0)
|
||||
{
|
||||
// optimization
|
||||
if (10 < $iOptimizationLimit && $iOptimizationLimit < \count($aMailFoldersHelper))
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Start optimization (limit:'.$iOptimizationLimit.') for '.\count($aMailFoldersHelper).' folders');
|
||||
}
|
||||
|
||||
$iForeachLimit = 1;
|
||||
|
||||
$aFilteredNames = array(
|
||||
'inbox',
|
||||
'sent', 'outbox', 'sentmail',
|
||||
'drafts',
|
||||
'junk', 'spam',
|
||||
'trash', 'bin',
|
||||
'archive', 'allmail', 'all',
|
||||
'starred', 'flagged', 'important'
|
||||
);
|
||||
|
||||
$aNewMailFoldersHelper = array();
|
||||
|
||||
$iCountLimit = $iForeachLimit;
|
||||
foreach ($aMailFoldersHelper as $iIndex => /* @var $oImapFolder \MailSo\Mail\Folder */ $oFolder)
|
||||
{
|
||||
// normal and subscribed only
|
||||
if ($oFolder && ($oFolder->IsSubscribed() || \in_array(\strtolower($oFolder->NameRaw()), $aFilteredNames)))
|
||||
{
|
||||
$aNewMailFoldersHelper[] = $oFolder;
|
||||
|
||||
$aMailFoldersHelper[$iIndex] = null;
|
||||
$iCountLimit--;
|
||||
}
|
||||
|
||||
if (0 > $iCountLimit)
|
||||
{
|
||||
if ($iOptimizationLimit < \count($aNewMailFoldersHelper))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
$iCountLimit = $iForeachLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$iCountLimit = $iForeachLimit;
|
||||
if ($iOptimizationLimit >= \count($aNewMailFoldersHelper))
|
||||
{
|
||||
// name filter
|
||||
foreach ($aMailFoldersHelper as $iIndex => /* @var $oImapFolder \MailSo\Mail\Folder */ $oFolder)
|
||||
{
|
||||
if ($oFolder && !\preg_match('/[{}\[\]]/', $oFolder->NameRaw()))
|
||||
{
|
||||
$aNewMailFoldersHelper[] = $oFolder;
|
||||
|
||||
$aMailFoldersHelper[$iIndex] = null;
|
||||
$iCountLimit--;
|
||||
}
|
||||
|
||||
if (0 > $iCountLimit)
|
||||
{
|
||||
if ($iOptimizationLimit < \count($aNewMailFoldersHelper))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
$iCountLimit = $iForeachLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$iCountLimit = $iForeachLimit;
|
||||
if ($iOptimizationLimit >= \count($aNewMailFoldersHelper))
|
||||
{
|
||||
// other
|
||||
foreach ($aMailFoldersHelper as $iIndex => /* @var $oImapFolder \MailSo\Mail\Folder */ $oFolder)
|
||||
{
|
||||
if ($oFolder)
|
||||
{
|
||||
$aNewMailFoldersHelper[] = $oFolder;
|
||||
|
||||
$aMailFoldersHelper[$iIndex] = null;
|
||||
$iCountLimit--;
|
||||
}
|
||||
|
||||
if (0 > $iCountLimit)
|
||||
{
|
||||
if ($iOptimizationLimit < \count($aNewMailFoldersHelper))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
$iCountLimit = $iForeachLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aMailFoldersHelper = $aNewMailFoldersHelper;
|
||||
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Result optimization: '.\count($aMailFoldersHelper).' folders');
|
||||
}
|
||||
}
|
||||
|
||||
return $aMailFoldersHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sParent = ''
|
||||
* @param string $sListPattern = '*'
|
||||
* @param bool $bUseListSubscribeStatus = false
|
||||
* @param int $iOptimizationLimit = 0
|
||||
*
|
||||
* @return \MailSo\Mail\FolderCollection|false
|
||||
*/
|
||||
public function Folders($sParent = '', $sListPattern = '*', $bUseListSubscribeStatus = true)
|
||||
public function Folders($sParent = '', $sListPattern = '*', $bUseListSubscribeStatus = true, $iOptimizationLimit = 0)
|
||||
{
|
||||
$oFolderCollection = false;
|
||||
|
||||
$aFolders = $this->oImapClient->FolderList($sParent, $sListPattern);
|
||||
|
||||
$aSubscribedFolders = null;
|
||||
if ($bUseListSubscribeStatus)
|
||||
{
|
||||
|
|
@ -2046,7 +2168,11 @@ class MailClient
|
|||
}
|
||||
}
|
||||
|
||||
$aFolders = $this->oImapClient->FolderList($sParent, $sListPattern);
|
||||
|
||||
$bOptimized = false;
|
||||
$aMailFoldersHelper = null;
|
||||
|
||||
if (\is_array($aFolders))
|
||||
{
|
||||
$aMailFoldersHelper = array();
|
||||
|
|
@ -2058,12 +2184,19 @@ class MailClient
|
|||
$oImapFolder->IsInbox()
|
||||
);
|
||||
}
|
||||
|
||||
$iCount = \count($aMailFoldersHelper);
|
||||
$aMailFoldersHelper = $this->folerListOptimization($aMailFoldersHelper, $iOptimizationLimit);
|
||||
|
||||
$bOptimized = $iCount !== \count($aMailFoldersHelper);
|
||||
}
|
||||
|
||||
if (\is_array($aMailFoldersHelper))
|
||||
{
|
||||
$oFolderCollection = FolderCollection::NewInstance();
|
||||
$oFolderCollection->InitByUnsortedMailFolderArray($aMailFoldersHelper);
|
||||
|
||||
$oFolderCollection->Optimized = $bOptimized;
|
||||
}
|
||||
|
||||
if ($oFolderCollection)
|
||||
|
|
|
|||
|
|
@ -4334,7 +4334,8 @@ class Actions
|
|||
if (null === $oFolderCollection)
|
||||
{
|
||||
$oFolderCollection = $this->MailClient()->Folders('', '*',
|
||||
!!$this->Config()->Get('labs', 'use_imap_list_subscribe', true)
|
||||
!!$this->Config()->Get('labs', 'use_imap_list_subscribe', true),
|
||||
(int) $this->Config()->Get('labs', 'imap_folder_list_limit', 200)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -4694,7 +4695,7 @@ class Actions
|
|||
*/
|
||||
public function DoMessageList()
|
||||
{
|
||||
// sleep(2);
|
||||
// \sleep(2);
|
||||
// throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantGetMessageList);
|
||||
|
||||
$sFolder = '';
|
||||
|
|
@ -4708,7 +4709,7 @@ class Actions
|
|||
$sRawKey = $this->GetActionParam('RawKey', '');
|
||||
$aValues = $this->getDecodedClientRawKeyValue($sRawKey, 9);
|
||||
|
||||
if (is_array($aValues) && 9 === count($aValues))
|
||||
if (\is_array($aValues) && 9 === \count($aValues))
|
||||
{
|
||||
$sFolder =(string) $aValues[0];
|
||||
$iOffset = (int) $aValues[1];
|
||||
|
|
@ -4753,7 +4754,7 @@ class Actions
|
|||
|
||||
$aExpandedThreadUid = \array_map(function ($sValue) {
|
||||
$sValue = \trim($sValue);
|
||||
return is_numeric($sValue) ? (int) $sValue : 0;
|
||||
return \is_numeric($sValue) ? (int) $sValue : 0;
|
||||
}, $aExpandedThreadUid);
|
||||
|
||||
$aExpandedThreadUid = \array_filter($aExpandedThreadUid, function ($iValue) {
|
||||
|
|
@ -8115,6 +8116,9 @@ class Actions
|
|||
case $iAttachmentsCount === $oAttachments->DocCount():
|
||||
$mResult['AttachmentsMainType'] = 'doc';
|
||||
break;
|
||||
case $iAttachmentsCount === $oAttachments->CertificateCount():
|
||||
$mResult['AttachmentsMainType'] = 'certificate';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -8382,6 +8386,7 @@ class Actions
|
|||
'Folder' => $mResponse->FolderName,
|
||||
'FolderHash' => $mResponse->FolderHash,
|
||||
'UidNext' => $mResponse->UidNext,
|
||||
'Optimized' => $mResponse->Optimized,
|
||||
'NewMessages' => $this->responseObject($mResponse->NewMessages),
|
||||
'LastCollapsedThreadUids' => $mResponse->LastCollapsedThreadUids,
|
||||
'Offset' => $mResponse->Offset,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Application extends \RainLoop\Config\AbstractConfig
|
|||
$sConfigPassword = (string) $this->Get('security', 'admin_password', '');
|
||||
|
||||
return 0 < \strlen($sPassword) &&
|
||||
($sPassword === $sConfigPassword || \md5(APP_SALT.$sPassword.APP_SALT) === $sConfigPassword);
|
||||
(($sPassword === $sConfigPassword && '12345' === $sConfigPassword) || \md5(APP_SALT.$sPassword.APP_SALT) === $sConfigPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -193,11 +193,6 @@ Examples:
|
|||
'enable' => array(false, 'Special option required for development purposes')
|
||||
),
|
||||
|
||||
'version' => array(
|
||||
'current' => array(''),
|
||||
'saved' => array('')
|
||||
),
|
||||
|
||||
'social' => array(
|
||||
'google_enable' => array(false, 'Google'),
|
||||
'google_enable_auth' => array(false),
|
||||
|
|
@ -271,6 +266,7 @@ Enables caching in the system'),
|
|||
'imap_message_list_count_limit_trigger' => array(0),
|
||||
'imap_message_list_date_filter' => array(0),
|
||||
'imap_large_thread_limit' => array(100),
|
||||
'imap_folder_list_limit' => array(200),
|
||||
'smtp_show_server_errors' => array(false),
|
||||
'curl_proxy' => array(''),
|
||||
'curl_proxy_auth' => array(''),
|
||||
|
|
@ -287,6 +283,11 @@ Enables caching in the system'),
|
|||
'use_local_proxy_for_external_images' => array(false),
|
||||
'dev_email' => array(''),
|
||||
'dev_password' => array('')
|
||||
),
|
||||
|
||||
'version' => array(
|
||||
'current' => array(''),
|
||||
'saved' => array('')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
</span>
|
||||
</div>
|
||||
<div class="subjectParent actionHandle dragHandle">
|
||||
<b style="color:red;margin-right:5px" data-bind="visible: isImportant">!</b>
|
||||
<b class="importantMark">!</b>
|
||||
<span class="subject emptySubjectText" data-bind="text: $root.emptySubjectValue"></span>
|
||||
<span class="subject-prefix" data-bind="text: subjectPrefix"></span><span class="subject-suffix" data-bind="text: subjectSuffix"></span>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
</span>
|
||||
</div>
|
||||
<div class="subjectParent actionHandle dragHandle">
|
||||
<b style="color:red;margin-right:5px" data-bind="visible: isImportant">!</b>
|
||||
<b class="importantMark">!</b>
|
||||
<span class="subject emptySubjectText" data-bind="text: $root.emptySubjectValue"></span>
|
||||
<span class="subject-prefix" data-bind="text: subjectPrefix"></span><span class="subject-suffix" data-bind="text: subjectSuffix"></span>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -308,12 +308,14 @@
|
|||
<div class="hidePreview">
|
||||
<div class="iconMain">
|
||||
<i class="attachmentIcon attachmentMainIcon" data-bind="css: iconClass()"></i>
|
||||
<i class="attachmentIconText attachmentMainIconText" data-bind="text: iconText()"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="showPreview">
|
||||
<a data-bind="css: {'attachmentImagePreview': isImage()}, attr: {'href': linkPreviewMain(), 'data-index': $index}" target="_blank">
|
||||
<div class="iconMain">
|
||||
<i class="attachmentIcon attachmentMainIcon" data-bind="css: iconClass()"></i>
|
||||
<i class="attachmentIconText attachmentMainIconText" data-bind="text: iconText()"></i>
|
||||
</div>
|
||||
<div class="iconBG" data-bind="attr: { 'style': linkThumbnailPreviewStyle() }"></div>
|
||||
<div class="iconPreview">
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<div class="modal hide b-compose" data-backdrop="static" data-bind="modal: modalVisibility, css: {'loading': saving() || sending()}">
|
||||
<div class="modal-header b-header-toolbar g-ui-user-select-none">
|
||||
<a class="btn btn-large button-send" data-bind="command: sendCommand, css: {'btn-danger': sendError, 'btn-warning': sendSuccessButSaveError }">
|
||||
<i data-bind="css: {'icon-paper-plane': !sending(), 'icon-spinner animated': sending(), 'icon-white': sendError() || sendSuccessButSaveError()}"></i>
|
||||
<i data-bind="css: {'icon-paper-plane': !sending(), 'icon-spinner animated big': sending(), 'icon-white': sendError() || sendSuccessButSaveError()}"></i>
|
||||
|
||||
<span class="i18n" data-i18n-text="COMPOSE/BUTTON_SEND"></span>
|
||||
</a>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue