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.folderInformation(cF);
} }
this.quota(); this.quota();
this.folderInformationMultiply(true); FolderUserStore.listStatusSupported() || this.folderInformationMultiply(true);
}, 1000); }, 1000);
setTimeout(() => Remote.appDelayStart(()=>0), 35000); setTimeout(() => Remote.appDelayStart(()=>0), 35000);

View file

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

View file

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

View file

@ -45,11 +45,6 @@ class Folder
*/ */
private $aFlagsLowerCase; private $aFlagsLowerCase;
/**
* @var array
*/
private $aExtended = array();
/** /**
* RFC 5464 * RFC 5464
*/ */
@ -132,22 +127,6 @@ class Folder
return 'INBOX' === \strtoupper($this->sFullNameRaw) || \in_array('\\inbox', $this->aFlagsLowerCase); 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 * @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 private function specificFolderList(bool $bIsSubscribeList, string $sParentFolderName = '', string $sListPattern = '*', bool $bUseListStatus = false) : array
{ {
$sCmd = 'LSUB'; $sCmd = 'LIST';
if (!$bIsSubscribeList)
{ $aParameters = array();
$sCmd = 'LIST'; $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[] = $this->EscapeString($sParentFolderName);
$aParameters[] = $this->EscapeString(\strlen(\trim($sListPattern)) ? $sListPattern : '*');
$aParameters = array(
$this->EscapeString($sParentFolderName),
$this->EscapeString($sListPattern)
);
if ($bUseListStatus && !$bIsSubscribeList && $this->IsSupported('LIST-STATUS')) if ($bUseListStatus && !$bIsSubscribeList && $this->IsSupported('LIST-STATUS'))
{ {
// RFC 5819
$aL = array( $aL = array(
Enumerations\FolderStatus::MESSAGES, Enumerations\FolderStatus::MESSAGES,
Enumerations\FolderStatus::UNSEEN, Enumerations\FolderStatus::UNSEEN,
Enumerations\FolderStatus::UIDNEXT Enumerations\FolderStatus::UIDNEXT
); );
// if ($this->IsSupported('CONDSTORE')) if ($this->IsSupported('CONDSTORE')) {
// { $aL[] = Enumerations\FolderStatus::HIGHESTMODSEQ;
// $aL[] = Enumerations\FolderStatus::HIGHESTMODSEQ; }
// }
$aParameters[] = 'RETURN'; $aReturnParams[] = 'STATUS';
$aParameters[] = array('STATUS', $aL); $aReturnParams[] = $aL;
} }
else else
{ {
$bUseListStatus = false; $bUseListStatus = false;
// RFC5258 }
if ($this->IsSupported('LIST-EXTENDED')) {
$aParameters[] = 'RETURN'; if ($aReturnParams) {
$aParameters[] = array('SUBSCRIBED'/*,'CHILDREN'*/); $aParameters[] = 'RETURN';
} $aParameters[] = $aReturnParams;
} }
$aReturn = $this->SendRequestGetResponse($sCmd, $aParameters)->getFoldersResult($sCmd, $bUseListStatus); $aReturn = $this->SendRequestGetResponse($sCmd, $aParameters)->getFoldersResult($sCmd, $bUseListStatus);
@ -1127,7 +1135,10 @@ class ImapClient extends \MailSo\Net\NetClient
break; 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() 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( return array(
'@Object' => 'Object/Folder', '@Object' => 'Object/Folder',
'Name' => $this->Name(), 'Name' => $this->Name(),
@ -294,6 +308,7 @@ class Folder implements \JsonSerializable
'Exists' => $this->bExists, 'Exists' => $this->bExists,
'Selectable' => $this->IsSelectable(), 'Selectable' => $this->IsSelectable(),
'Flags' => $this->FlagsLowerCase(), 'Flags' => $this->FlagsLowerCase(),
// 'Extended' => $aExtended,
'Metadata' => $this->oImapFolder->Metadata() 'Metadata' => $this->oImapFolder->Metadata()
); );
} }

View file

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

View file

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

View file

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

View file

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