From 2b3889392dacaaf68efcb7ba136d5452894f4380 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Fri, 26 Sep 2014 20:44:04 +0400 Subject: [PATCH] Added "custom-system-folders" plugin Small fixes --- dev/Common/Utils.js | 7 +- dev/View/Popup/FolderSystem.js | 2 +- plugins/custom-system-folders/LICENSE | 20 +++ plugins/custom-system-folders/README | 1 + plugins/custom-system-folders/VERSION | 1 + plugins/custom-system-folders/index.php | 139 ++++++++++++++++++ .../0.0.0/app/libraries/RainLoop/Actions.php | 45 ++++-- 7 files changed, 202 insertions(+), 13 deletions(-) create mode 100644 plugins/custom-system-folders/LICENSE create mode 100644 plugins/custom-system-folders/README create mode 100644 plugins/custom-system-folders/VERSION create mode 100644 plugins/custom-system-folders/index.php diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index 69bfaa9fd..bc8f5608d 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -1652,7 +1652,8 @@ * @param {boolean=} bBuildUnvisible * @return {Array} */ - Utils.folderListOptionsBuilder = function (aSystem, aList, aDisabled, aHeaderLines, iUnDeep, fDisableCallback, fVisibleCallback, fRenameCallback, bSystem, bBuildUnvisible) + Utils.folderListOptionsBuilder = function (aSystem, aList, aDisabled, aHeaderLines, + iUnDeep, fDisableCallback, fVisibleCallback, fRenameCallback, bSystem, bBuildUnvisible) { var /** @@ -1666,8 +1667,8 @@ aResult = [] ; - bSystem = !Utils.isNormal(bSystem) ? 0 < aSystem.length : bSystem; bBuildUnvisible = Utils.isUnd(bBuildUnvisible) ? false : !!bBuildUnvisible; + bSystem = !Utils.isNormal(bSystem) ? 0 < aSystem.length : bSystem; iUnDeep = !Utils.isNormal(iUnDeep) ? 0 : iUnDeep; fDisableCallback = Utils.isNormal(fDisableCallback) ? fDisableCallback : null; fVisibleCallback = Utils.isNormal(fVisibleCallback) ? fVisibleCallback : null; @@ -1727,7 +1728,7 @@ for (iIndex = 0, iLen = aList.length; iIndex < iLen; iIndex++) { oItem = aList[iIndex]; - if (oItem.subScribed() || !oItem.existen) + if (oItem.subScribed() || !oItem.existen || bBuildUnvisible) { if (fVisibleCallback ? fVisibleCallback.call(null, oItem) : true) { diff --git a/dev/View/Popup/FolderSystem.js b/dev/View/Popup/FolderSystem.js index e78ce425d..9cd095ca7 100644 --- a/dev/View/Popup/FolderSystem.js +++ b/dev/View/Popup/FolderSystem.js @@ -38,7 +38,7 @@ return Utils.folderListOptionsBuilder([], Data.folderList(), Data.folderListSystemNames(), [ ['', this.sChooseOnText], [Consts.Values.UnuseOptionValue, this.sUnuseText] - ]); + ], null, null, null, null, null, true); }, this); var diff --git a/plugins/custom-system-folders/LICENSE b/plugins/custom-system-folders/LICENSE new file mode 100644 index 000000000..4a4ca8d81 --- /dev/null +++ b/plugins/custom-system-folders/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2014 RainLoop Team + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/plugins/custom-system-folders/README b/plugins/custom-system-folders/README new file mode 100644 index 000000000..38b29fe96 --- /dev/null +++ b/plugins/custom-system-folders/README @@ -0,0 +1 @@ +custom-sytem-folders \ No newline at end of file diff --git a/plugins/custom-system-folders/VERSION b/plugins/custom-system-folders/VERSION new file mode 100644 index 000000000..9f8e9b69a --- /dev/null +++ b/plugins/custom-system-folders/VERSION @@ -0,0 +1 @@ +1.0 \ No newline at end of file diff --git a/plugins/custom-system-folders/index.php b/plugins/custom-system-folders/index.php new file mode 100644 index 000000000..b9f6d2b97 --- /dev/null +++ b/plugins/custom-system-folders/index.php @@ -0,0 +1,139 @@ +sSentFolder = \trim($this->Config()->Get('plugin', 'sent_folder', '')); + $this->sDraftsFolder = \trim($this->Config()->Get('plugin', 'drafts_folder', '')); + $this->sSpamFolder = \trim($this->Config()->Get('plugin', 'spam_folder', '')); + $this->sTrashFolder = \trim($this->Config()->Get('plugin', 'trash_folder', '')); + $this->sArchiveFolder = \trim($this->Config()->Get('plugin', 'archive_folder', '')); + + $this->addHook('filter.system-folders-names', 'FilterSystemFoldersNames'); + $this->addHook('filter.folders-system-types', 'FilterFoldersSystemTypes'); + } + + /** + * @param \RainLoop\Account $oAccount + * @param array $aSystemTypes + */ + public function FilterFoldersSystemTypes($oAccount, &$aSystemTypes) + { + if ($oAccount) + { + $aSystemTypes = array(); + if (0 < \strlen($this->sSentFolder)) + { + $aSystemTypes[] = \MailSo\Imap\Enumerations\FolderType::SENT; + } + + if (0 < \strlen($this->sDraftsFolder)) + { + $aSystemTypes[] = \MailSo\Imap\Enumerations\FolderType::DRAFTS; + } + + if (0 < \strlen($this->sSpamFolder)) + { + $aSystemTypes[] = \MailSo\Imap\Enumerations\FolderType::JUNK; + } + + if (0 < \strlen($this->sTrashFolder)) + { + $aSystemTypes[] = \MailSo\Imap\Enumerations\FolderType::TRASH; + } + + if (0 < \strlen($this->sArchiveFolder)) + { + $aSystemTypes[] = \MailSo\Imap\Enumerations\FolderType::ALL; + } + } + } + + private function helperFolderType($sFolderName, $iType, &$aPrepend, &$aSystemFolderNames) + { + if (0 < \strlen($sFolderName) && '{@system@}' !== $sFolderName) + { + $aPrepend[$sFolderName] = $iType; + if (isset($aSystemFolderNames[$sFolderName])) + { + unset($aSystemFolderNames[$sFolderName]); + } + } + } + + /** + * @param \RainLoop\Account $oAccount + * @param array $aSystemFolderNames + */ + public function FilterSystemFoldersNames($oAccount, &$aSystemFolderNames) + { + $aPrepend = array(); + if ($oAccount && \is_array($aSystemFolderNames)) + { + $this->helperFolderType($this->sSentFolder, \MailSo\Imap\Enumerations\FolderType::SENT, + $aPrepend, $aSystemFolderNames); + + $this->helperFolderType($this->sDraftsFolder, \MailSo\Imap\Enumerations\FolderType::DRAFTS, + $aPrepend, $aSystemFolderNames); + + $this->helperFolderType($this->sSpamFolder, \MailSo\Imap\Enumerations\FolderType::JUNK, + $aPrepend, $aSystemFolderNames); + + $this->helperFolderType($this->sTrashFolder, \MailSo\Imap\Enumerations\FolderType::TRASH, + $aPrepend, $aSystemFolderNames); + + $this->helperFolderType($this->sArchiveFolder, \MailSo\Imap\Enumerations\FolderType::ALL, + $aPrepend, $aSystemFolderNames); + + if (0 < \count($aPrepend)) + { + $aSystemFolderNames = \array_merge($aPrepend, $aSystemFolderNames); + } + } + } + + /** + * @return array + */ + public function configMapping() + { + return array( + \RainLoop\Plugins\Property::NewInstance('sent_folder')->SetLabel('Sent') + ->SetDefaultValue('Sent'), + \RainLoop\Plugins\Property::NewInstance('drafts_folder')->SetLabel('Drafts') + ->SetDefaultValue('Drafts'), + \RainLoop\Plugins\Property::NewInstance('spam_folder')->SetLabel('Spam') + ->SetDefaultValue('Spam'), + \RainLoop\Plugins\Property::NewInstance('trash_folder')->SetLabel('Trash') + ->SetDefaultValue('Trash'), + \RainLoop\Plugins\Property::NewInstance('archive_folder')->SetLabel('Archive') + ->SetDefaultValue('Archive') + ); + } +} \ No newline at end of file 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 3bdbca43f..f427dc185 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -3755,9 +3755,9 @@ class Actions 'Send Mail' => \MailSo\Imap\Enumerations\FolderType::SENT, 'Send Mails' => \MailSo\Imap\Enumerations\FolderType::SENT, - 'Draft' => \MailSo\Imap\Enumerations\FolderType::DRAFTS, - 'Drafts' => \MailSo\Imap\Enumerations\FolderType::DRAFTS, + + 'Draft' => \MailSo\Imap\Enumerations\FolderType::DRAFTS, 'Draft Mail' => \MailSo\Imap\Enumerations\FolderType::DRAFTS, 'Draft Mails' => \MailSo\Imap\Enumerations\FolderType::DRAFTS, 'Drafts Mail' => \MailSo\Imap\Enumerations\FolderType::DRAFTS, @@ -3801,7 +3801,7 @@ class Actions $aFolders =& $oFolders->GetAsArray(); if (\is_array($aFolders) && 0 < \count($aFolders)) { - if ($bListFolderTypes) + if ($bListFolderTypes && false) { foreach ($aFolders as $oFolder) { @@ -3816,7 +3816,10 @@ class Actions { $aResult[$iFolderListType] = $oFolder->FullNameRaw(); } - + } + + foreach ($aFolders as $oFolder) + { $oSub = $oFolder->SubFolders(); if ($oSub && 0 < $oSub->Count()) { @@ -3829,9 +3832,11 @@ class Actions foreach ($aFolders as $oFolder) { $sName = $oFolder->Name(); - if (isset($aMap[$sName])) + $sFullName = $oFolder->FullName(); + + if (isset($aMap[$sName], $aMap[$sFullName])) { - $iFolderType = $aMap[$sName]; + $iFolderType = isset($aMap[$sName]) ? $aMap[$sName] : $aMap[$sFullName]; if (!isset($aResult[$iFolderType]) && \in_array($iFolderType, array( \MailSo\Imap\Enumerations\FolderType::SENT, \MailSo\Imap\Enumerations\FolderType::DRAFTS, @@ -3843,7 +3848,10 @@ class Actions $aResult[$iFolderType] = $oFolder->FullNameRaw(); } } - + } + + foreach ($aFolders as $oFolder) + { $oSub = $oFolder->SubFolders(); if ($oSub && 0 < $oSub->Count()) { @@ -3890,7 +3898,10 @@ class Actions { $bDoItAgain = false; $sNamespace = $oFolderCollection->GetNamespace(); - $sNamespace = empty($sNamespace) ? '' : \substr($sNamespace, 0, -1); + $sParent = empty($sNamespace) ? '' : \substr($sNamespace, 0, -1); + + $oInboxFolder = $oFolderCollection->GetByFullNameRaw('INBOX'); + $sDelimiter = $oInboxFolder ? $oInboxFolder->Delimiter() : '/'; $aList = array(); $aMap = $this->systemFoldersNames($oAccount); @@ -3924,9 +3935,25 @@ class Actions $mFolderNameToCreate = \array_search($iType, $aMap); if (!empty($mFolderNameToCreate)) { + $iPos = \strrpos($mFolderNameToCreate, $sDelimiter); + if (false !== $iPos) + { + $mNewParent = \substr($mFolderNameToCreate, 0, $iPos); + $mNewFolderNameToCreate = \substr($mFolderNameToCreate, $iPos + 1); + if (0 < \strlen($mNewFolderNameToCreate)) + { + $mFolderNameToCreate = $mNewFolderNameToCreate; + } + + if (0 < \strlen($mNewParent)) + { + $sParent = 0 < \strlen($sParent) ? $sParent.$sDelimiter.$mNewParent : $mNewParent; + } + } + try { - if ($this->MailClient()->FolderCreate($mFolderNameToCreate, $sNamespace)) + if ($this->MailClient()->FolderCreate($mFolderNameToCreate, $sParent)) { $bDoItAgain = true; }