From b68d04aacd8c359ee1b1633459b52c3eb86082c6 Mon Sep 17 00:00:00 2001 From: djmaze Date: Thu, 15 Oct 2020 12:23:11 +0200 Subject: [PATCH] Bugfix: inboxFolderName was incorrect You could have potentionally deleted INBOX and other issues --- dev/Common/Cache.js | 28 +++++++++---------- dev/Model/Folder.js | 10 ++----- dev/Model/FolderCollection.js | 9 ++++-- .../0.0.0/app/libraries/RainLoop/Actions.php | 2 ++ 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/dev/Common/Cache.js b/dev/Common/Cache.js index 66c62f41b..64b222d50 100644 --- a/dev/Common/Cache.js +++ b/dev/Common/Cache.js @@ -7,7 +7,7 @@ let FOLDERS_CACHE = {}, FOLDERS_UID_NEXT_CACHE = {}, MESSAGE_FLAGS_CACHE = {}, NEW_MESSAGE_CACHE = {}, - inboxFolderName = ''; + inboxFolderName = 'INBOX'; const REQUESTED_MESSAGE_CACHE = {}; @@ -79,7 +79,14 @@ export function clearNewMessageCache() { * @returns {string} */ export function getFolderInboxName() { - return inboxFolderName || 'INBOX'; + return inboxFolderName; +} + +/** + * @returns {string} + */ +export function setFolderInboxName(name) { + inboxFolderName = name; } /** @@ -93,12 +100,11 @@ export function getFolderFullNameRaw(folderHash) { /** * @param {string} folderHash * @param {string} folderFullNameRaw + * @param {?FolderModel} folder */ -export function setFolderFullNameRaw(folderHash, folderFullNameRaw) { +export function setFolder(folderHash, folderFullNameRaw, folder) { + FOLDERS_CACHE[folderFullNameRaw] = folder; FOLDERS_NAME_CACHE[folderHash] = folderFullNameRaw; - if (!inboxFolderName || 'INBOX' === folderFullNameRaw) { - inboxFolderName = folderFullNameRaw; - } } /** @@ -145,19 +151,11 @@ export function getFolderFromCacheList(folderFullNameRaw) { return folderFullNameRaw && FOLDERS_CACHE[folderFullNameRaw] ? FOLDERS_CACHE[folderFullNameRaw] : null; } -/** - * @param {string} folderFullNameRaw - * @param {?FolderModel} folder - */ -export function setFolderToCacheList(folderFullNameRaw, folder) { - FOLDERS_CACHE[folderFullNameRaw] = folder; -} - /** * @param {string} folderFullNameRaw */ export function removeFolderFromCacheList(folderFullNameRaw) { - setFolderToCacheList(folderFullNameRaw, null); + delete FOLDERS_CACHE[folderFullNameRaw]; } /** diff --git a/dev/Model/Folder.js b/dev/Model/Folder.js index db0aa434d..b8c2bad28 100644 --- a/dev/Model/Folder.js +++ b/dev/Model/Folder.js @@ -3,7 +3,6 @@ import ko from 'ko'; import { FolderType } from 'Common/Enums'; import { isPosNumeric } from 'Common/UtilsUser'; import { i18n, trigger as translatorTrigger } from 'Common/Translator'; -import { getFolderInboxName } from 'Common/Cache'; import { AbstractModel } from 'Knoin/AbstractModel'; @@ -56,8 +55,6 @@ class FolderModel extends AbstractModel { * @returns {FolderModel} */ initComputed() { - const inboxFolderName = getFolderInboxName(); - this.isInbox = ko.computed(() => FolderType.Inbox === this.type()); this.hasSubScribedSubfolders = ko.computed( @@ -136,11 +133,11 @@ class FolderModel extends AbstractModel { this.canBeDeleted = ko.computed(() => { const bSystem = this.isSystemFolder(); - return !bSystem && !this.subFolders().length && inboxFolderName !== this.fullNameRaw; + return !bSystem && !this.subFolders().length; }); this.canBeSubScribed = ko.computed( - () => !this.isSystemFolder() && this.selectable && inboxFolderName !== this.fullNameRaw + () => !this.isSystemFolder() && this.selectable ); this.canBeChecked = this.canBeSubScribed; @@ -263,7 +260,6 @@ class FolderModel extends AbstractModel { */ initByJson(json) { let bResult = false; - const sInboxFolderName = getFolderInboxName(); if (json && 'Object/Folder' === json['@Object']) { this.name(json.Name); @@ -278,8 +274,6 @@ class FolderModel extends AbstractModel { this.subScribed(!!json.IsSubscribed); this.checkable(!!json.Checkable); - this.type(sInboxFolderName === this.fullNameRaw ? FolderType.Inbox : FolderType.User); - bResult = true; } diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index a879cba1c..3f44456e8 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -2,7 +2,7 @@ import { AbstractCollectionModel } from 'Model/AbstractCollection'; import { UNUSED_OPTION_VALUE } from 'Common/Consts'; import { pInt } from 'Common/Utils'; -import { ClientSideKeyName, ServerFolderType } from 'Common/Enums'; +import { ClientSideKeyName, FolderType, ServerFolderType } from 'Common/Enums'; import * as Cache from 'Common/Cache'; import * as Local from 'Storage/Client'; @@ -55,8 +55,11 @@ export class FolderCollectionModel extends AbstractCollectionModel if (!oCacheFolder) { oCacheFolder = FolderModel.newInstanceFromJson(oFolder); if (oCacheFolder) { - Cache.setFolderToCacheList(oFolder.FullNameRaw, oCacheFolder); - Cache.setFolderFullNameRaw(oCacheFolder.fullNameHash, oFolder.FullNameRaw, oCacheFolder); + if (oFolder.FullNameRaw == result.SystemFolders[ServerFolderType.INBOX]) { + oCacheFolder.type(FolderType.Inbox); + Cache.setFolderInboxName(oFolder.FullNameRaw); + } + Cache.setFolder(oCacheFolder.fullNameHash, oFolder.FullNameRaw, oCacheFolder); } } diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php index 615a162f6..6834f9339 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -3108,6 +3108,7 @@ NewThemeLink IncludeCss TemplatesLink LangLink IncludeBackground PluginsLink Aut { $iFolderListType = $oFolder->GetFolderListType(); if (!isset($aResult[$iFolderListType]) && \in_array($iFolderListType, array( + \MailSo\Imap\Enumerations\FolderType::INBOX, \MailSo\Imap\Enumerations\FolderType::SENT, \MailSo\Imap\Enumerations\FolderType::DRAFTS, \MailSo\Imap\Enumerations\FolderType::JUNK, @@ -3139,6 +3140,7 @@ NewThemeLink IncludeCss TemplatesLink LangLink IncludeBackground PluginsLink Aut { $iFolderType = isset($aMap[$sName]) ? $aMap[$sName] : $aMap[$sFullName]; if (!isset($aResult[$iFolderType]) && \in_array($iFolderType, array( + \MailSo\Imap\Enumerations\FolderType::INBOX, \MailSo\Imap\Enumerations\FolderType::SENT, \MailSo\Imap\Enumerations\FolderType::DRAFTS, \MailSo\Imap\Enumerations\FolderType::JUNK,