From 542a1c9624aeb55bbfaa2a5040177fcdfb7c9c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=A4rdeman?= Date: Tue, 24 Aug 2021 23:08:46 +0200 Subject: [PATCH 1/4] [snappymail] No need to call trim() twice Mostly a cosmetic change, but stil. --- snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 d1c5df73a..7934cfdb5 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 @@ -2083,13 +2083,13 @@ class MailClient */ public function FolderCreate(string $sFolderNameInUtf8, string $sFolderParentFullNameRaw = '', bool $bSubscribeOnCreation = true, string $sDelimiter = '') : self { - if (!strlen(\trim($sFolderNameInUtf8))) + $sFolderNameInUtf8 = \trim($sFolderNameInUtf8); + + if (0 === \strlen($sFolderNameInUtf8)) { throw new \MailSo\Base\Exceptions\InvalidArgumentException; } - $sFolderNameInUtf8 = \trim($sFolderNameInUtf8); - if (0 === \strlen($sDelimiter) || 0 < \strlen(\trim($sFolderParentFullNameRaw))) { $aFolders = $this->oImapClient->FolderList('', 0 === \strlen(\trim($sFolderParentFullNameRaw)) ? 'INBOX' : $sFolderParentFullNameRaw); From b658b79264c9d2e34e45bf7ff3306a0d44b3fb48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=A4rdeman?= Date: Tue, 24 Aug 2021 23:20:27 +0200 Subject: [PATCH 2/4] [snappymail] Remove some more overuse of trim() The FolderCreate() function also misses using trim() sometimes on $sFolderParentFullNameRaw, so this should be more correct as well. --- .../v/0.0.0/app/libraries/MailSo/Mail/MailClient.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 7934cfdb5..746115826 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 @@ -2084,26 +2084,27 @@ class MailClient public function FolderCreate(string $sFolderNameInUtf8, string $sFolderParentFullNameRaw = '', bool $bSubscribeOnCreation = true, string $sDelimiter = '') : self { $sFolderNameInUtf8 = \trim($sFolderNameInUtf8); + $sFolderParentFullNameRaw = \trim($sFolderParentFullNameRaw); if (0 === \strlen($sFolderNameInUtf8)) { throw new \MailSo\Base\Exceptions\InvalidArgumentException; } - if (0 === \strlen($sDelimiter) || 0 < \strlen(\trim($sFolderParentFullNameRaw))) + if (0 === \strlen($sDelimiter) || 0 < \strlen($sFolderParentFullNameRaw)) { - $aFolders = $this->oImapClient->FolderList('', 0 === \strlen(\trim($sFolderParentFullNameRaw)) ? 'INBOX' : $sFolderParentFullNameRaw); + $aFolders = $this->oImapClient->FolderList('', 0 === \strlen($sFolderParentFullNameRaw) ? 'INBOX' : $sFolderParentFullNameRaw); if (!$aFolders) { // TODO throw new \MailSo\Mail\Exceptions\RuntimeException( - 0 === \strlen(trim($sFolderParentFullNameRaw)) + 0 === \strlen($sFolderParentFullNameRaw) ? 'Cannot get folder delimiter' : 'Cannot create folder in non-existen parent folder'); } $sDelimiter = $aFolders[0]->Delimiter(); - if (0 < \strlen($sDelimiter) && 0 < \strlen(\trim($sFolderParentFullNameRaw))) + if (0 < \strlen($sDelimiter) && 0 < \strlen($sFolderParentFullNameRaw)) { $sFolderParentFullNameRaw .= $sDelimiter; } From 0190170edd2a6738c81c61d77bcac81a86b6921f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=A4rdeman?= Date: Wed, 25 Aug 2021 00:12:46 +0200 Subject: [PATCH 3/4] [snappymail] Include subfolders in folder list rebuild Subfolders also need to be taken into consideration, otherwise subfolder deletion/creation won't be reflected in the UI. Fixes #72 --- dev/Model/FolderCollection.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index 54ed0b753..1332f7e14 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -68,12 +68,12 @@ export class FolderCollectionModel extends AbstractCollectionModel return super.reviveFromJson(object, oFolder => { let oCacheFolder = Cache.getFolderFromCacheList(oFolder.FullNameRaw); -/* + if (oCacheFolder) { oFolder.SubFolders = FolderCollectionModel.reviveFromJson(oFolder.SubFolders); oFolder.SubFolders && oCacheFolder.subFolders(oFolder.SubFolders); } -*/ + if (!oCacheFolder && (oCacheFolder = FolderModel.reviveFromJson(oFolder))) { if (1 == SystemFolders.indexOf(oFolder.FullNameRaw)) { oCacheFolder.type(FolderType.Inbox); From 17f107057ae94b49e9a4265899bc3ff25130f2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20H=C3=A4rdeman?= Date: Wed, 25 Aug 2021 00:19:39 +0200 Subject: [PATCH 4/4] [snappymail] Rework FolderCollectionModel .js a bit Following the previous bugfix, rework the .js code a bit to reduce the amount of nested ifdeffery. --- dev/Model/FolderCollection.js | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index 1332f7e14..9d427687c 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -72,9 +72,11 @@ export class FolderCollectionModel extends AbstractCollectionModel if (oCacheFolder) { oFolder.SubFolders = FolderCollectionModel.reviveFromJson(oFolder.SubFolders); oFolder.SubFolders && oCacheFolder.subFolders(oFolder.SubFolders); - } + } else { + oCacheFolder = FolderModel.reviveFromJson(oFolder); + if (!oCacheFolder) + return null; - if (!oCacheFolder && (oCacheFolder = FolderModel.reviveFromJson(oFolder))) { if (1 == SystemFolders.indexOf(oFolder.FullNameRaw)) { oCacheFolder.type(FolderType.Inbox); Cache.setFolderInboxName(oFolder.FullNameRaw); @@ -82,28 +84,26 @@ export class FolderCollectionModel extends AbstractCollectionModel Cache.setFolder(oCacheFolder.fullNameHash, oFolder.FullNameRaw, oCacheFolder); } - if (oCacheFolder) { - let type = SystemFolders.indexOf(oFolder.FullNameRaw); - if (1 < type) { - oCacheFolder.type(type); + let type = SystemFolders.indexOf(oFolder.FullNameRaw); + if (1 < type) { + oCacheFolder.type(type); + } + + oCacheFolder.collapsed(!expandedFolders + || !isArray(expandedFolders) + || !expandedFolders.includes(oCacheFolder.fullNameHash)); + + if (oFolder.Extended) { + if (oFolder.Extended.Hash) { + Cache.setFolderHash(oCacheFolder.fullNameRaw, oFolder.Extended.Hash); } - oCacheFolder.collapsed(!expandedFolders - || !isArray(expandedFolders) - || !expandedFolders.includes(oCacheFolder.fullNameHash)); + if (null != oFolder.Extended.MessageCount) { + oCacheFolder.messageCountAll(oFolder.Extended.MessageCount); + } - if (oFolder.Extended) { - if (oFolder.Extended.Hash) { - Cache.setFolderHash(oCacheFolder.fullNameRaw, oFolder.Extended.Hash); - } - - if (null != oFolder.Extended.MessageCount) { - oCacheFolder.messageCountAll(oFolder.Extended.MessageCount); - } - - if (null != oFolder.Extended.MessageUnseenCount) { - oCacheFolder.messageCountUnread(oFolder.Extended.MessageUnseenCount); - } + if (null != oFolder.Extended.MessageUnseenCount) { + oCacheFolder.messageCountUnread(oFolder.Extended.MessageUnseenCount); } } return oCacheFolder;