From 17b1deb95b9b6a6644c2b4ad9a2499976c6e54fa Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 13 Mar 2023 10:46:40 +0100 Subject: [PATCH] FolderInformation() use jsonSerialize() --- dev/Common/Folders.js | 3 +- .../MailSo/Imap/FolderInformation.php | 8 ++- .../app/libraries/MailSo/Mail/MailClient.php | 59 ++++++++----------- .../libraries/RainLoop/Actions/Folders.php | 24 +++----- 4 files changed, 40 insertions(+), 54 deletions(-) diff --git a/dev/Common/Folders.js b/dev/Common/Folders.js index 9c9ee7104..f00927184 100644 --- a/dev/Common/Folders.js +++ b/dev/Common/Folders.js @@ -121,7 +121,7 @@ folderInformation = (folder, list) => { Remote.request('FolderInformation', (iError, data) => { if (!iError && data.Result) { const result = data.Result, - folderFromCache = getFolderFromCacheList(result.folder); + folderFromCache = getFolderFromCacheList(result.name); if (folderFromCache) { const oldHash = folderFromCache.etag, unreadCountChange = (folderFromCache.unreadEmails() !== result.unreadEmails); @@ -167,7 +167,6 @@ folderInformationMultiply = (boot = false) => { const utc = Date.now(); oData.Result.forEach(item => { const folder = getFolderFromCacheList(item.name); - if (folder) { const oldHash = folder.etag, unreadCountChange = folder.unreadEmails() !== item.unreadEmails; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/FolderInformation.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/FolderInformation.php index a8073ea29..745e00c90 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/FolderInformation.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/FolderInformation.php @@ -50,8 +50,6 @@ class FolderInformation implements \JsonSerializable $result = array( 'id' => $this->MAILBOXID, 'name' => $this->FullName, - 'flags' => $this->Flags, - 'permanentFlags' => $this->PermanentFlags, 'uidNext' => $this->UIDNEXT, 'uidValidity' => $this->UIDVALIDITY ); @@ -71,6 +69,12 @@ class FolderInformation implements \JsonSerializable if ($this->etag) { $result['etag'] = $this->etag; } + if ($this->Flags) { + $result['flags'] = $this->Flags; + } + if ($this->PermanentFlags) { + $result['permanentFlags'] = $this->PermanentFlags; + } return $result; } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php index 1792b0c98..07a43c323 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php @@ -330,45 +330,38 @@ class MailClient */ public function FolderInformation(string $sFolderName, int $iPrevUidNext = 0, SequenceSet $oRange = null) : array { - $aFlags = array(); - if ($oRange && \count($oRange)) { -// $oInfo = $this->oImapClient->FolderExamine($sFolderName); - $oInfo = $this->oImapClient->FolderStatusAndSelect($sFolderName); - $aFetchResponse = $this->oImapClient->Fetch(array( - FetchType::UID, - FetchType::FLAGS - ), (string) $oRange, $oRange->UID); - foreach ($aFetchResponse as $oFetchResponse) { - $iUid = (int) $oFetchResponse->GetFetchValue(FetchType::UID); - $aLowerFlags = \array_map('mb_strtolower', \array_map('\\MailSo\\Base\\Utils::Utf7ModifiedToUtf8', $oFetchResponse->GetFetchValue(FetchType::FLAGS))); - $aFlags[] = array( - 'uid' => $iUid, - 'flags' => $aLowerFlags - ); + if ($oRange) { +// $aInfo = $this->oImapClient->FolderExamine($sFolderName)->jsonSerialize(); + $aInfo = $this->oImapClient->FolderStatusAndSelect($sFolderName)->jsonSerialize(); + $aInfo['messagesFlags'] = array(); + if (\count($oRange)) { + $aFetchResponse = $this->oImapClient->Fetch(array( + FetchType::UID, + FetchType::FLAGS + ), (string) $oRange, $oRange->UID); + foreach ($aFetchResponse as $oFetchResponse) { + $iUid = (int) $oFetchResponse->GetFetchValue(FetchType::UID); + $aLowerFlags = \array_map('mb_strtolower', \array_map('\\MailSo\\Base\\Utils::Utf7ModifiedToUtf8', $oFetchResponse->GetFetchValue(FetchType::FLAGS))); + $aInfo['messagesFlags'][] = array( + 'uid' => $iUid, + 'flags' => $aLowerFlags + ); + } } } else { - $oInfo = $this->oImapClient->FolderStatus($sFolderName); + $aInfo = $this->oImapClient->FolderStatus($sFolderName)->jsonSerialize(); } - return array( - 'folder' => $sFolderName, - '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( + if ($iPrevUidNext) { + $aInfo['newMessages'] = $this->getFolderNextMessageInformation( $sFolderName, $iPrevUidNext, - \intval($oInfo->UIDNEXT) - ) - ); + \intval($aInfo['uidNext']) + ); + } + +// $aInfo['appendLimit'] = $aInfo['appendLimit'] ?: $this->oImapClient->AppendLimit(); + return $aInfo; } /** diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php index 1a64526c3..b5430e6ff 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php @@ -302,23 +302,13 @@ trait Folders $aFolders = \array_unique($aFolders); foreach ($aFolders as $sFolder) { - if (\strlen($sFolder) && 'INBOX' !== \strtoupper($sFolder)) { - try - { - $aInboxInformation = $this->MailClient()->FolderInformation($sFolder); - if (isset($aInboxInformation['folder'])) { - $aResult[] = [ - 'name' => $aInboxInformation['folder'], - 'etag' => $aInboxInformation['etag'], - 'totalEmails' => $aInboxInformation['totalEmails'], - 'unreadEmails' => $aInboxInformation['unreadEmails'], - ]; - } - } - catch (\Throwable $oException) - { - $this->Logger()->WriteException($oException); - } + try + { + $aResult[] = $this->MailClient()->FolderInformation($sFolder); + } + catch (\Throwable $oException) + { + $this->Logger()->WriteException($oException); } } }