mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 00:47:04 +03:00
Cleanup & Speedup *Collection objects
This commit is contained in:
parent
f6fdb69c65
commit
ebfde6e360
12 changed files with 169 additions and 209 deletions
|
|
@ -27,33 +27,41 @@ class AttachmentCollection extends \MailSo\Base\Collection
|
|||
return new self();
|
||||
}
|
||||
|
||||
public function append(Attachment $oFolder, bool $bToTop = false) : void
|
||||
{
|
||||
parent::append($oFolder, $bToTop);
|
||||
}
|
||||
|
||||
public function InlineCount() : int
|
||||
{
|
||||
$aList = $this->FilterList(function ($oAttachment) {
|
||||
return $oAttachment && $oAttachment->IsInline();
|
||||
});
|
||||
|
||||
return \is_array($aList) ? \count($aList) : 0;
|
||||
$iCount = 0;
|
||||
foreach ($this as $oAttachment) {
|
||||
if ($oAttachment && $oAttachment->IsInline()) {
|
||||
++$iCount;
|
||||
}
|
||||
}
|
||||
return $iCount;
|
||||
}
|
||||
|
||||
public function NonInlineCount() : int
|
||||
{
|
||||
$aList = $this->FilterList(function ($oAttachment) {
|
||||
return $oAttachment && !$oAttachment->IsInline();
|
||||
});
|
||||
|
||||
return \is_array($aList) ? \count($aList) : 0;
|
||||
$iCount = 0;
|
||||
foreach ($this as $oAttachment) {
|
||||
if ($oAttachment && !$oAttachment->IsInline()) {
|
||||
++$iCount;
|
||||
}
|
||||
}
|
||||
return $iCount;
|
||||
}
|
||||
|
||||
public function SpecData() : array
|
||||
{
|
||||
return $this->MapList(function ($oAttachment) {
|
||||
if ($oAttachment)
|
||||
{
|
||||
return array($oAttachment->FileName(true), $oAttachment->MimeType());
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
$aResult = array();
|
||||
foreach ($this as $oAttachment) {
|
||||
$aResult[] = $oAttachment
|
||||
? array($oAttachment->FileName(true), $oAttachment->MimeType())
|
||||
: null;
|
||||
}
|
||||
return $aResult;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,15 +155,14 @@ class Folder
|
|||
|
||||
public function HasVisibleSubFolders() : bool
|
||||
{
|
||||
$sList = array();
|
||||
if ($this->oSubFolders)
|
||||
{
|
||||
$sList = $this->oSubFolders->FilterList(function (\MailSo\Mail\Folder $oFolder) {
|
||||
return $oFolder->IsSubscribed();
|
||||
});
|
||||
if ($this->oSubFolders) {
|
||||
foreach ($this->oSubFolders as $oFolder) {
|
||||
if ($oFolder->IsSubscribed()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0 < \count($sList);
|
||||
return false;
|
||||
}
|
||||
|
||||
public function IsSubscribed() : bool
|
||||
|
|
|
|||
|
|
@ -58,10 +58,15 @@ class FolderCollection extends \MailSo\Base\Collection
|
|||
return new self();
|
||||
}
|
||||
|
||||
public function GetByFullNameRaw(string $sFullNameRaw) : ?\MailSo\Mail\Folder
|
||||
public function append(Folder $oFolder, bool $bToTop = false) : void
|
||||
{
|
||||
parent::append($oFolder, $bToTop);
|
||||
}
|
||||
|
||||
public function GetByFullNameRaw(string $sFullNameRaw) : ?Folder
|
||||
{
|
||||
$mResult = null;
|
||||
foreach ($this as /* @var $oFolder \MailSo\Mail\Folder */ $oFolder)
|
||||
foreach ($this as $oFolder)
|
||||
{
|
||||
if ($oFolder->FullNameRaw() === $sFullNameRaw)
|
||||
{
|
||||
|
|
@ -75,10 +80,6 @@ class FolderCollection extends \MailSo\Base\Collection
|
|||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mResult = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +89,7 @@ class FolderCollection extends \MailSo\Base\Collection
|
|||
public function CountRec() : int
|
||||
{
|
||||
$iResult = $this->Count();
|
||||
foreach ($this as /* @var $oFolder \MailSo\Mail\Folder */ $oFolder)
|
||||
foreach ($this as $oFolder)
|
||||
{
|
||||
if ($oFolder)
|
||||
{
|
||||
|
|
@ -135,7 +136,7 @@ class FolderCollection extends \MailSo\Base\Collection
|
|||
$this->Clear();
|
||||
|
||||
$aSortedByLenImapFolders = array();
|
||||
foreach ($aUnsortedMailFolders as /* @var $oMailFolder \MailSo\Mail\Folder */ $oMailFolder)
|
||||
foreach ($aUnsortedMailFolders as /* @var $oMailFolder Folder */ $oMailFolder)
|
||||
{
|
||||
$aSortedByLenImapFolders[$oMailFolder->FullNameRaw()] =& $oMailFolder;
|
||||
unset($oMailFolder);
|
||||
|
|
@ -143,7 +144,7 @@ class FolderCollection extends \MailSo\Base\Collection
|
|||
unset($aUnsortedMailFolders);
|
||||
|
||||
$aAddedFolders = array();
|
||||
foreach ($aSortedByLenImapFolders as /* @var $oMailFolder \MailSo\Mail\Folder */ $oMailFolder)
|
||||
foreach ($aSortedByLenImapFolders as /* @var $oMailFolder Folder */ $oMailFolder)
|
||||
{
|
||||
$sDelimiter = $oMailFolder->Delimiter();
|
||||
$aFolderExplode = \explode($sDelimiter, $oMailFolder->FullNameRaw());
|
||||
|
|
@ -181,7 +182,7 @@ class FolderCollection extends \MailSo\Base\Collection
|
|||
return \strnatcmp($oFolderA->FullNameRaw(), $oFolderB->FullNameRaw());
|
||||
});
|
||||
|
||||
foreach ($aSortedByLenImapFolders as /* @var $oMailFolder \MailSo\Mail\Folder */ $oMailFolder)
|
||||
foreach ($aSortedByLenImapFolders as $oMailFolder)
|
||||
{
|
||||
$this->AddWithPositionSearch($oMailFolder);
|
||||
unset($oMailFolder);
|
||||
|
|
@ -190,14 +191,14 @@ class FolderCollection extends \MailSo\Base\Collection
|
|||
unset($aSortedByLenImapFolders);
|
||||
}
|
||||
|
||||
public function AddWithPositionSearch(\MailSo\Mail\Folder $oMailFolder) : bool
|
||||
public function AddWithPositionSearch(Folder $oMailFolder) : bool
|
||||
{
|
||||
$oItemFolder = null;
|
||||
$bIsAdded = false;
|
||||
|
||||
foreach ($this as /* @var $oItemFolder \MailSo\Mail\Folder */ $oItemFolder)
|
||||
foreach ($this as $oItemFolder)
|
||||
{
|
||||
if ($oMailFolder instanceof \MailSo\Mail\Folder &&
|
||||
if ($oMailFolder instanceof Folder &&
|
||||
0 === \strpos($oMailFolder->FullNameRaw(), $oItemFolder->FullNameRaw().$oItemFolder->Delimiter()))
|
||||
{
|
||||
if ($oItemFolder->SubFolders(true)->AddWithPositionSearch($oMailFolder))
|
||||
|
|
@ -209,7 +210,7 @@ class FolderCollection extends \MailSo\Base\Collection
|
|||
}
|
||||
}
|
||||
|
||||
if (!$bIsAdded && $oMailFolder instanceof \MailSo\Mail\Folder)
|
||||
if (!$bIsAdded && $oMailFolder instanceof Folder)
|
||||
{
|
||||
$bIsAdded = true;
|
||||
$this->append($oMailFolder);
|
||||
|
|
|
|||
|
|
@ -1842,8 +1842,7 @@ class MailClient
|
|||
|
||||
if ($bUseThreadSortIfSupported && 0 === $iThreadUid && \is_array($mAllThreads) && 0 < \count($mAllThreads))
|
||||
{
|
||||
$oMessageCollection->ForeachList(function (/* @var $oMessage \MailSo\Mail\Message */ $oMessage) use ($mAllThreads) {
|
||||
|
||||
foreach ($oMessageCollection as $oMessage) {
|
||||
$iUid = $oMessage->Uid();
|
||||
if (isset($mAllThreads[$iUid]) && \is_array($mAllThreads[$iUid]) && 0 < \count($mAllThreads[$iUid]))
|
||||
{
|
||||
|
|
@ -1853,7 +1852,7 @@ class MailClient
|
|||
$oMessage->SetThreads(\array_map('trim', $aSubThreads));
|
||||
unset($aSubThreads);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return $oMessageCollection;
|
||||
|
|
|
|||
|
|
@ -491,7 +491,9 @@ class Message
|
|||
$this->oCc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::CC, $bCharsetAutoDetect);
|
||||
$this->oBcc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::BCC, $bCharsetAutoDetect);
|
||||
|
||||
$oHeaders->PopulateEmailColectionByDkim($this->oFrom);
|
||||
if ($this->oFrom) {
|
||||
$oHeaders->PopulateEmailColectionByDkim($this->oFrom);
|
||||
}
|
||||
|
||||
$this->oSender = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::SENDER, $bCharsetAutoDetect);
|
||||
$this->oReplyTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::REPLY_TO, $bCharsetAutoDetect);
|
||||
|
|
@ -582,32 +584,28 @@ class Message
|
|||
}
|
||||
|
||||
$sDraftInfo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_DRAFT_INFO);
|
||||
if (0 < \strlen($sDraftInfo))
|
||||
{
|
||||
if (0 < \strlen($sDraftInfo)) {
|
||||
$sType = '';
|
||||
$sFolder = '';
|
||||
$sUid = '';
|
||||
|
||||
\MailSo\Mime\ParameterCollection::NewInstance($sDraftInfo)
|
||||
->ForeachList(function ($oParameter) use (&$sType, &$sFolder, &$sUid) {
|
||||
$oParameters = \MailSo\Mime\ParameterCollection::NewInstance($sDraftInfo);
|
||||
foreach ($oParameters as $oParameter) {
|
||||
switch (\strtolower($oParameter->Name()))
|
||||
{
|
||||
case 'type':
|
||||
$sType = $oParameter->Value();
|
||||
break;
|
||||
case 'uid':
|
||||
$sUid = $oParameter->Value();
|
||||
break;
|
||||
case 'folder':
|
||||
$sFolder = \base64_decode($oParameter->Value());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (\strtolower($oParameter->Name()))
|
||||
{
|
||||
case 'type':
|
||||
$sType = $oParameter->Value();
|
||||
break;
|
||||
case 'uid':
|
||||
$sUid = $oParameter->Value();
|
||||
break;
|
||||
case 'folder':
|
||||
$sFolder = \base64_decode($oParameter->Value());
|
||||
break;
|
||||
}
|
||||
})
|
||||
;
|
||||
|
||||
if (0 < \strlen($sType) && 0 < \strlen($sFolder) && 0 < \strlen($sUid))
|
||||
{
|
||||
if (0 < \strlen($sType) && 0 < \strlen($sFolder) && 0 < \strlen($sUid)) {
|
||||
$this->aDraftInfo = array($sType, $sUid, $sFolder);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,6 +89,11 @@ class MessageCollection extends \MailSo\Base\Collection
|
|||
return new self();
|
||||
}
|
||||
|
||||
public function append(Message $oMessage, bool $bToTop = false) : void
|
||||
{
|
||||
parent::append($oMessage, $bToTop);
|
||||
}
|
||||
|
||||
public function Clear() : void
|
||||
{
|
||||
parent::Clear();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue