FolderInformation() use jsonSerialize()

This commit is contained in:
the-djmaze 2023-03-13 10:46:40 +01:00
parent 59b3fe70b6
commit 17b1deb95b
4 changed files with 40 additions and 54 deletions

View file

@ -121,7 +121,7 @@ folderInformation = (folder, list) => {
Remote.request('FolderInformation', (iError, data) => { Remote.request('FolderInformation', (iError, data) => {
if (!iError && data.Result) { if (!iError && data.Result) {
const result = data.Result, const result = data.Result,
folderFromCache = getFolderFromCacheList(result.folder); folderFromCache = getFolderFromCacheList(result.name);
if (folderFromCache) { if (folderFromCache) {
const oldHash = folderFromCache.etag, const oldHash = folderFromCache.etag,
unreadCountChange = (folderFromCache.unreadEmails() !== result.unreadEmails); unreadCountChange = (folderFromCache.unreadEmails() !== result.unreadEmails);
@ -167,7 +167,6 @@ folderInformationMultiply = (boot = false) => {
const utc = Date.now(); const utc = Date.now();
oData.Result.forEach(item => { oData.Result.forEach(item => {
const folder = getFolderFromCacheList(item.name); const folder = getFolderFromCacheList(item.name);
if (folder) { if (folder) {
const oldHash = folder.etag, const oldHash = folder.etag,
unreadCountChange = folder.unreadEmails() !== item.unreadEmails; unreadCountChange = folder.unreadEmails() !== item.unreadEmails;

View file

@ -50,8 +50,6 @@ class FolderInformation implements \JsonSerializable
$result = array( $result = array(
'id' => $this->MAILBOXID, 'id' => $this->MAILBOXID,
'name' => $this->FullName, 'name' => $this->FullName,
'flags' => $this->Flags,
'permanentFlags' => $this->PermanentFlags,
'uidNext' => $this->UIDNEXT, 'uidNext' => $this->UIDNEXT,
'uidValidity' => $this->UIDVALIDITY 'uidValidity' => $this->UIDVALIDITY
); );
@ -71,6 +69,12 @@ class FolderInformation implements \JsonSerializable
if ($this->etag) { if ($this->etag) {
$result['etag'] = $this->etag; $result['etag'] = $this->etag;
} }
if ($this->Flags) {
$result['flags'] = $this->Flags;
}
if ($this->PermanentFlags) {
$result['permanentFlags'] = $this->PermanentFlags;
}
return $result; return $result;
} }
} }

View file

@ -330,10 +330,11 @@ class MailClient
*/ */
public function FolderInformation(string $sFolderName, int $iPrevUidNext = 0, SequenceSet $oRange = null) : array public function FolderInformation(string $sFolderName, int $iPrevUidNext = 0, SequenceSet $oRange = null) : array
{ {
$aFlags = array(); if ($oRange) {
if ($oRange && \count($oRange)) { // $aInfo = $this->oImapClient->FolderExamine($sFolderName)->jsonSerialize();
// $oInfo = $this->oImapClient->FolderExamine($sFolderName); $aInfo = $this->oImapClient->FolderStatusAndSelect($sFolderName)->jsonSerialize();
$oInfo = $this->oImapClient->FolderStatusAndSelect($sFolderName); $aInfo['messagesFlags'] = array();
if (\count($oRange)) {
$aFetchResponse = $this->oImapClient->Fetch(array( $aFetchResponse = $this->oImapClient->Fetch(array(
FetchType::UID, FetchType::UID,
FetchType::FLAGS FetchType::FLAGS
@ -341,36 +342,28 @@ class MailClient
foreach ($aFetchResponse as $oFetchResponse) { foreach ($aFetchResponse as $oFetchResponse) {
$iUid = (int) $oFetchResponse->GetFetchValue(FetchType::UID); $iUid = (int) $oFetchResponse->GetFetchValue(FetchType::UID);
$aLowerFlags = \array_map('mb_strtolower', \array_map('\\MailSo\\Base\\Utils::Utf7ModifiedToUtf8', $oFetchResponse->GetFetchValue(FetchType::FLAGS))); $aLowerFlags = \array_map('mb_strtolower', \array_map('\\MailSo\\Base\\Utils::Utf7ModifiedToUtf8', $oFetchResponse->GetFetchValue(FetchType::FLAGS)));
$aFlags[] = array( $aInfo['messagesFlags'][] = array(
'uid' => $iUid, 'uid' => $iUid,
'flags' => $aLowerFlags 'flags' => $aLowerFlags
); );
} }
}
} else { } else {
$oInfo = $this->oImapClient->FolderStatus($sFolderName); $aInfo = $this->oImapClient->FolderStatus($sFolderName)->jsonSerialize();
} }
return array( if ($iPrevUidNext) {
'folder' => $sFolderName, $aInfo['newMessages'] = $this->getFolderNextMessageInformation(
'totalEmails' => $oInfo->MESSAGES,
'unreadEmails' => $oInfo->UNSEEN,
'uidNext' => $oInfo->UIDNEXT,
'uidValidity' => $oInfo->UIDVALIDITY,
'highestModSeq' => $oInfo->HIGHESTMODSEQ,
'appendLimit' => $oInfo->APPENDLIMIT ?: $this->oImapClient->AppendLimit(),
'mailboxId' => $oInfo->MAILBOXID ?: '',
// 'flags' => $oInfo->Flags,
// 'permanentFlags' => $oInfo->PermanentFlags,
'etag' => $oInfo->etag,
'messagesFlags' => $aFlags,
'newMessages' => $this->getFolderNextMessageInformation(
$sFolderName, $sFolderName,
$iPrevUidNext, $iPrevUidNext,
\intval($oInfo->UIDNEXT) \intval($aInfo['uidNext'])
)
); );
} }
// $aInfo['appendLimit'] = $aInfo['appendLimit'] ?: $this->oImapClient->AppendLimit();
return $aInfo;
}
/** /**
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException

View file

@ -302,18 +302,9 @@ trait Folders
$aFolders = \array_unique($aFolders); $aFolders = \array_unique($aFolders);
foreach ($aFolders as $sFolder) { foreach ($aFolders as $sFolder) {
if (\strlen($sFolder) && 'INBOX' !== \strtoupper($sFolder)) {
try try
{ {
$aInboxInformation = $this->MailClient()->FolderInformation($sFolder); $aResult[] = $this->MailClient()->FolderInformation($sFolder);
if (isset($aInboxInformation['folder'])) {
$aResult[] = [
'name' => $aInboxInformation['folder'],
'etag' => $aInboxInformation['etag'],
'totalEmails' => $aInboxInformation['totalEmails'],
'unreadEmails' => $aInboxInformation['unreadEmails'],
];
}
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
@ -321,7 +312,6 @@ trait Folders
} }
} }
} }
}
return $this->DefaultResponse($aResult); return $this->DefaultResponse($aResult);
} }