No need to call folderInformationMultiply at boot when LIST-STATUS is supported

This commit is contained in:
djmaze 2021-10-27 15:30:19 +02:00
parent 8d07ab87fa
commit d0210bd09a
10 changed files with 97 additions and 83 deletions

View file

@ -855,7 +855,7 @@ class AppUser extends AbstractApp {
this.folderInformation(cF);
}
this.quota();
this.folderInformationMultiply(true);
FolderUserStore.listStatusSupported() || this.folderInformationMultiply(true);
}, 1000);
setTimeout(() => Remote.appDelayStart(()=>0), 35000);

View file

@ -40,6 +40,7 @@ export class FolderCollectionModel extends AbstractCollectionModel
this.IsMetadataSupported
this.IsThreadsSupported
this.IsSortSupported
this.IsExtendedSupported
this.Namespace;
this.Optimized
this.SystemFolders
@ -147,6 +148,7 @@ export class FolderCollectionModel extends AbstractCollectionModel
FolderUserStore.folderListOptimized(!!this.Optimized);
FolderUserStore.sortSupported(!!this.IsSortSupported);
FolderUserStore.metadataSupported(!!this.IsMetadataSupported);
FolderUserStore.listStatusSupported(!!this.IsListStatusSupported);
FolderUserStore.sentFolder(normalizeFolder(SettingsGet('SentFolder')));
FolderUserStore.draftFolder(normalizeFolder(SettingsGet('DraftFolder')));

View file

@ -24,6 +24,7 @@ export const FolderUserStore = new class {
*/
sortSupported: false,
metadataSupported: false,
listStatusSupported: false,
// sortMode: '',
sentFolder: '',

View file

@ -45,11 +45,6 @@ class Folder
*/
private $aFlagsLowerCase;
/**
* @var array
*/
private $aExtended = array();
/**
* RFC 5464
*/
@ -132,22 +127,6 @@ class Folder
return 'INBOX' === \strtoupper($this->sFullNameRaw) || \in_array('\\inbox', $this->aFlagsLowerCase);
}
/**
* @param mixed $mData
*/
public function SetExtended(string $sName, $mData) : void
{
$this->aExtended[$sName] = $mData;
}
/**
* @return mixed
*/
public function GetExtended(string $sName)
{
return isset($this->aExtended[$sName]) ? $this->aExtended[$sName] : null;
}
/**
* @param mixed $mData
*/

View file

@ -441,43 +441,51 @@ class ImapClient extends \MailSo\Net\NetClient
*/
private function specificFolderList(bool $bIsSubscribeList, string $sParentFolderName = '', string $sListPattern = '*', bool $bUseListStatus = false) : array
{
$sCmd = 'LSUB';
if (!$bIsSubscribeList)
{
$sCmd = 'LIST';
$sCmd = 'LIST';
$aParameters = array();
$aReturnParams = array();
if ($bIsSubscribeList) {
$sCmd = 'LSUB';
} else if ($this->IsSupported('LIST-EXTENDED')) {
// RFC 5258
$aReturnParams[] = 'SUBSCRIBED';
// $aReturnParams[] = 'CHILDREN';
if ($bIsSubscribeList) {
$aParameters[] = ['SUBSCRIBED'/*,'REMOTE','RECURSIVEMATCH'*/];
} else {
// $aParameters[0] = '()';
}
}
$sListPattern = \strlen(\trim($sListPattern)) ? $sListPattern : '*';
$aParameters = array(
$this->EscapeString($sParentFolderName),
$this->EscapeString($sListPattern)
);
$aParameters[] = $this->EscapeString($sParentFolderName);
$aParameters[] = $this->EscapeString(\strlen(\trim($sListPattern)) ? $sListPattern : '*');
if ($bUseListStatus && !$bIsSubscribeList && $this->IsSupported('LIST-STATUS'))
{
// RFC 5819
$aL = array(
Enumerations\FolderStatus::MESSAGES,
Enumerations\FolderStatus::UNSEEN,
Enumerations\FolderStatus::UIDNEXT
);
// if ($this->IsSupported('CONDSTORE'))
// {
// $aL[] = Enumerations\FolderStatus::HIGHESTMODSEQ;
// }
if ($this->IsSupported('CONDSTORE')) {
$aL[] = Enumerations\FolderStatus::HIGHESTMODSEQ;
}
$aParameters[] = 'RETURN';
$aParameters[] = array('STATUS', $aL);
$aReturnParams[] = 'STATUS';
$aReturnParams[] = $aL;
}
else
{
$bUseListStatus = false;
// RFC5258
if ($this->IsSupported('LIST-EXTENDED')) {
$aParameters[] = 'RETURN';
$aParameters[] = array('SUBSCRIBED'/*,'CHILDREN'*/);
}
}
if ($aReturnParams) {
$aParameters[] = 'RETURN';
$aParameters[] = $aReturnParams;
}
$aReturn = $this->SendRequestGetResponse($sCmd, $aParameters)->getFoldersResult($sCmd, $bUseListStatus);
@ -1127,7 +1135,10 @@ class ImapClient extends \MailSo\Net\NetClient
break;
}
unset($oResponse);
// RFC 5530
if (\is_array($oResponse->OptionalResponse) && 'CLIENTBUG' === $oResponse->OptionalResponse[0]) {
// The server has detected a client bug.
}
}
}

View file

@ -283,6 +283,20 @@ class Folder implements \JsonSerializable
public function jsonSerialize()
{
/*
$aExtended = null;
$aStatus = $this->oImapFolder->getStatusItems();
if ($aStatus && isset($aStatus['MESSAGES'], $aStatus['UNSEEN'], $aStatus['UIDNEXT'])) {
$aExtended = array(
'MessageCount' => (int) $aStatus['MESSAGES'],
'MessageUnseenCount' => (int) $aStatus['UNSEEN'],
'UidNext' => (int) $aStatus['UIDNEXT'],
// 'Hash' => $this->MailClient()->GenerateFolderHash(
// $this->FullNameRaw(), $aStatus['MESSAGES'], $aStatus['UIDNEXT'],
// empty($aStatus['HIGHESTMODSEQ']) ? 0 : $aStatus['HIGHESTMODSEQ'])
);
}
*/
return array(
'@Object' => 'Object/Folder',
'Name' => $this->Name(),
@ -294,6 +308,7 @@ class Folder implements \JsonSerializable
'Exists' => $this->bExists,
'Selectable' => $this->IsSelectable(),
'Flags' => $this->FlagsLowerCase(),
// 'Extended' => $aExtended,
'Metadata' => $this->oImapFolder->Metadata()
);
}

View file

@ -42,6 +42,11 @@ class FolderCollection extends \MailSo\Base\Collection
*/
public $IsSortSupported = false;
/**
* @var bool
*/
public $IsListStatusSupported = false;
/**
* @var bool
*/
@ -161,6 +166,7 @@ class FolderCollection extends \MailSo\Base\Collection
'IsMetadataSupported' => $this->IsMetadataSupported,
'IsThreadsSupported' => $this->IsThreadsSupported,
'IsSortSupported' => $this->IsSortSupported,
'IsListStatusSupported' => $this->IsListStatusSupported,
'Optimized' => $this->Optimized,
'CountRec' => $this->CountRec(),
'SystemFolders' => empty($this->SystemFolders) ? null : $this->SystemFolders

View file

@ -153,7 +153,7 @@ class MailClient
if (\is_array($aCustomUids))
{
if (0 < \count($aCustomUids))
if (\count($aCustomUids))
{
$this->oImapClient->MessageStoreFlag(implode(',', $aCustomUids), true, array($sMessageFlag), $sStoreAction);
}
@ -254,7 +254,7 @@ class MailClient
);
$aFetchResponse = $this->oImapClient->Fetch(array(\MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE), $iIndex, $bIndexIsUid);
if (0 < \count($aFetchResponse) && isset($aFetchResponse[0]))
if (\count($aFetchResponse) && isset($aFetchResponse[0]))
{
$oBodyStructure = $aFetchResponse[0]->GetFetchBodyStructure();
if ($oBodyStructure)
@ -271,7 +271,7 @@ class MailClient
}
$aSignatureParts = $oBodyStructure->SearchByContentType('application/pgp-signature');
if (is_array($aSignatureParts) && 0 < \count($aSignatureParts))
if (is_array($aSignatureParts) && \count($aSignatureParts))
{
foreach ($aSignatureParts as $oPart)
{
@ -287,7 +287,7 @@ class MailClient
}
$aFetchResponse = $this->oImapClient->Fetch($aFetchItems, $iIndex, $bIndexIsUid);
if (0 < \count($aFetchResponse))
if (\count($aFetchResponse))
{
$oMessage = Message::NewFetchResponseInstance(
$sFolderName, $aFetchResponse[0], $oBodyStructure);
@ -632,7 +632,7 @@ class MailClient
$bSelect = false;
if (0 < \count($aUids))
if (\count($aUids))
{
if (!$bSelect)
{
@ -803,7 +803,7 @@ class MailClient
$mMatch = array();
\preg_match_all('/('.$sReg.'):([^\s]*)/i', $sSearch, $mMatch);
if (\is_array($mMatch) && isset($mMatch[1]) && \is_array($mMatch[1]) && 0 < \count($mMatch[1]))
if (\is_array($mMatch) && isset($mMatch[1]) && \is_array($mMatch[1]) && \count($mMatch[1]))
{
if (\is_array($mMatch[0]))
{
@ -1128,7 +1128,7 @@ class MailClient
else
{
$mMap = $this->threadArrayMap($mItem);
if (0 < \count($mMap))
if (\count($mMap))
{
$aNew = \array_merge($aNew, $mMap);
}
@ -1150,7 +1150,7 @@ class MailClient
{
$aResult[] = $aMap;
}
else if (0 < \count($aMap))
else if (\count($aMap))
{
$aResult[] = $aMap[0];
}
@ -1313,7 +1313,7 @@ class MailClient
$mFirst = \array_shift($aItem);
if (!empty($mFirst))
{
$aTemp[$mFirst] = 0 < \count($aItem) ? $aItem : $mFirst;
$aTemp[$mFirst] = \count($aItem) ? $aItem : $mFirst;
}
}
}
@ -1361,7 +1361,7 @@ class MailClient
*/
public function MessageListByRequestIndexOrUids(MessageCollection $oMessageCollection, array $aRequestIndexOrUids, bool $bIndexAsUid, bool $bSimple = false)
{
if (0 < \count($aRequestIndexOrUids))
if (\count($aRequestIndexOrUids))
{
$aFetchResponse = $this->oImapClient->Fetch(array(
\MailSo\Imap\Enumerations\FetchType::INDEX,
@ -1375,7 +1375,7 @@ class MailClient
$this->getEnvelopeOrHeadersRequestString()
), \MailSo\Base\Utils::PrepareFetchSequence($aRequestIndexOrUids), $bIndexAsUid);
if (0 < \count($aFetchResponse))
if (\count($aFetchResponse))
{
$aFetchIndexArray = array();
foreach ($aFetchResponse as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ $oFetchResponseItem)
@ -1653,7 +1653,7 @@ class MailClient
$aSearchedUids = $this->GetUids($oCacher, $sSearch, $sFilter,
$oMessageCollection->FolderName, $oMessageCollection->FolderHash);
if (0 < \count($aSearchedUids))
if (\count($aSearchedUids))
{
$aFlippedSearchedUids = \array_flip($aSearchedUids);
@ -1694,7 +1694,7 @@ class MailClient
$oMessageCollection->MessageUnseenCount = $iMessageUnseenCount;
$oMessageCollection->MessageResultCount = \count($aUids);
if (0 < \count($aUids))
if (\count($aUids))
{
$aRequestUids = \array_slice($aUids, $iOffset, $iLimit);
$this->MessageListByRequestIndexOrUids($oMessageCollection, $aRequestUids, true);
@ -1934,8 +1934,8 @@ class MailClient
}
}
$aFolders = $this->oImapClient->FolderList($sParent, $sListPattern);
// $aFolders = $this->oImapClient->FolderStatusList($sParent, $sListPattern);
// $aFolders = $this->oImapClient->FolderList($sParent, $sListPattern);
$aFolders = $this->oImapClient->FolderStatusList($sParent, $sListPattern);
if (!$aFolders) {
return null;
}
@ -1959,6 +1959,7 @@ class MailClient
$oFolderCollection->IsMetadataSupported = $this->oImapClient->IsSupported('METADATA');
$oFolderCollection->IsThreadsSupported = $this->IsThreadsSupported();
$oFolderCollection->IsSortSupported = $this->oImapClient->IsSupported('SORT');
$oFolderCollection->IsListStatusSupported = $this->oImapClient->IsSupported('LIST-STATUS');
$oFolderCollection->Optimized = $iCount !== \count($aMailFoldersHelper);
$aSortedByLenImapFolders = array();

View file

@ -10,6 +10,14 @@ use \MailSo\Imap\Enumerations\FolderType;
trait Folders
{
private function getFolderCollection(bool $HideUnsubscribed) : ?\MailSo\Mail\FolderCollection
{
return $this->MailClient()->Folders('', '*',
$HideUnsubscribed,
(int) $this->Config()->Get('labs', 'imap_folder_list_limit', 200)
);
}
public function DoFolders() : array
{
$oAccount = $this->initMailClientConnection();
@ -20,13 +28,9 @@ trait Folders
$HideUnsubscribed = (bool) $oSettingsLocal->GetConf('HideUnsubscribed', $HideUnsubscribed);
}
$oFolderCollection = $this->MailClient()->Folders('',
'*',
$HideUnsubscribed,
(int) $this->Config()->Get('labs', 'imap_folder_list_limit', 200)
);
$oFolderCollection = $this->getFolderCollection($HideUnsubscribed);
if ($oFolderCollection instanceof \MailSo\Mail\FolderCollection)
if ($oFolderCollection)
{
$this->Plugins()->RunHook('filter.folders-post', array($oAccount, $oFolderCollection));
@ -126,10 +130,7 @@ trait Folders
if ($bDoItAgain)
{
$oFolderCollection = $this->MailClient()->Folders('', '*',
$HideUnsubscribed,
(int) $this->Config()->Get('labs', 'imap_folder_list_limit', 200)
);
$oFolderCollection = $this->getFolderCollection($HideUnsubscribed);
if ($oFolderCollection)
{
@ -406,7 +407,7 @@ trait Folders
$aFolders = \array_unique($aFolders);
foreach ($aFolders as $sFolder)
{
if (0 < \strlen($sFolder) && 'INBOX' !== \strtoupper($sFolder))
if (\strlen($sFolder) && 'INBOX' !== \strtoupper($sFolder))
{
try
{

View file

@ -404,19 +404,17 @@ trait Response
if ($mResponse instanceof \MailSo\Mail\Folder)
{
$aExtended = null;
// $mStatus = $mResponse->Status();
// if (\is_array($mStatus) && isset($mStatus['MESSAGES'], $mStatus['UNSEEN'], $mStatus['UIDNEXT']))
// {
// $aExtended = array(
// 'MessageCount' => (int) $mStatus['MESSAGES'],
// 'MessageUnseenCount' => (int) $mStatus['UNSEEN'],
// 'UidNext' => (int) $mStatus['UIDNEXT'],
// 'Hash' => $this->MailClient()->GenerateFolderHash(
// $mResponse->FullNameRaw(), $mStatus['MESSAGES'], $mStatus['UIDNEXT'],
// empty($mStatus['HIGHESTMODSEQ']) ? '' : $mStatus['HIGHESTMODSEQ'])
// );
// }
$aStatus = $mResponse->Status();
if ($aStatus && isset($aStatus['MESSAGES'], $aStatus['UNSEEN'], $aStatus['UIDNEXT'])) {
$aExtended = array(
'MessageCount' => (int) $aStatus['MESSAGES'],
'MessageUnseenCount' => (int) $aStatus['UNSEEN'],
'UidNext' => (int) $aStatus['UIDNEXT'],
'Hash' => $this->MailClient()->GenerateFolderHash(
$mResponse->FullNameRaw(), $aStatus['MESSAGES'], $aStatus['UIDNEXT'],
empty($aStatus['HIGHESTMODSEQ']) ? 0 : $aStatus['HIGHESTMODSEQ'])
);
}
if (null === $this->aCheckableFolder)
{