From e023a5d6ab755e3c7eaf4c90558f4c74896e89cd Mon Sep 17 00:00:00 2001 From: djmaze Date: Wed, 6 Jan 2021 01:06:16 +0100 Subject: [PATCH] Prepare Sieve Filtering feature for advanced editing/handling --- dev/Settings/User/Filters.js | 8 +- dev/Stores/User/Filter.js | 2 +- dev/View/Popup/Filter.js | 81 +++++++++---------- .../Providers/Filters/SieveStorage.php | 62 +++++++------- 4 files changed, 72 insertions(+), 81 deletions(-) diff --git a/dev/Settings/User/Filters.js b/dev/Settings/User/Filters.js index 9d5cd444a..8dea23d2c 100644 --- a/dev/Settings/User/Filters.js +++ b/dev/Settings/User/Filters.js @@ -103,11 +103,11 @@ class FiltersUserSettings { data.Result.Filters.map(aItem => FilterModel.reviveFromJson(aItem)).filter(v => v) ); - this.modules(data.Result.Modules ? data.Result.Modules : {}); + this.modules(data.Result.Capa); - this.filterRaw(data.Result.Raw || ''); - this.filterRaw.capa(Array.isArray(data.Result.Capa) ? data.Result.Capa.join(' ') : ''); - this.filterRaw.active(!!data.Result.RawIsActive); + this.filterRaw(data.Result.Scripts['rainloop.user.raw'].body); + this.filterRaw.capa(data.Result.Capa.join(' ')); + this.filterRaw.active(data.Result.Scripts['rainloop.user.raw'].active); this.filterRaw.allow(!!data.Result.RawIsAllow); } else { this.filters([]); diff --git a/dev/Stores/User/Filter.js b/dev/Stores/User/Filter.js index a3a01ed22..119fc9df7 100644 --- a/dev/Stores/User/Filter.js +++ b/dev/Stores/User/Filter.js @@ -4,7 +4,7 @@ class FilterUserStore { constructor() { ko.addObservablesTo(this, { capa: '', - modules: {}, + modules: [], raw: '' }); diff --git a/dev/View/Popup/Filter.js b/dev/View/Popup/Filter.js index 1b8806807..a7331c9b3 100644 --- a/dev/View/Popup/Filter.js +++ b/dev/View/Popup/Filter.js @@ -67,50 +67,12 @@ class FilterPopupView extends AbstractViewNext { populateOptions() { this.actionTypeOptions([]); - // this.actionTypeOptions.push({'id': FiltersAction.None, - // 'name': i18n('POPUPS_FILTER/SELECT_ACTION_NONE')}); - - const modules = this.modules(); - if (modules) { - if (modules.markasread) { - this.allowMarkAsRead(true); - } - - if (modules.moveto) { - this.actionTypeOptions.push({ - 'id': FiltersAction.MoveTo, - 'name': i18n('POPUPS_FILTER/SELECT_ACTION_MOVE_TO') - }); - } - - if (modules.redirect) { - this.actionTypeOptions.push({ - 'id': FiltersAction.Forward, - 'name': i18n('POPUPS_FILTER/SELECT_ACTION_FORWARD_TO') - }); - } - - if (modules.reject) { - this.actionTypeOptions.push({ 'id': FiltersAction.Reject, 'name': i18n('POPUPS_FILTER/SELECT_ACTION_REJECT') }); - } - - if (modules.vacation) { - this.actionTypeOptions.push({ - 'id': FiltersAction.Vacation, - 'name': i18n('POPUPS_FILTER/SELECT_ACTION_VACATION_MESSAGE') - }); - } - } - - this.actionTypeOptions.push({ 'id': FiltersAction.Discard, 'name': i18n('POPUPS_FILTER/SELECT_ACTION_DISCARD') }); - this.fieldOptions([ { 'id': FilterConditionField.From, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_FROM') }, { 'id': FilterConditionField.Recipient, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_RECIPIENTS') }, { 'id': FilterConditionField.Subject, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_SUBJECT') }, { 'id': FilterConditionField.Size, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_SIZE') }, - { 'id': FilterConditionField.Header, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_HEADER') }, - { 'id': FilterConditionField.Body, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_BODY') } + { 'id': FilterConditionField.Header, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_HEADER') } ]); this.typeOptions([ @@ -120,10 +82,47 @@ class FilterPopupView extends AbstractViewNext { { 'id': FilterConditionType.NotEqualTo, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_NOT_EQUAL_TO') } ]); - if (modules && modules.regex) { - this.typeOptions.push({ 'id': FilterConditionType.Regex, 'name': 'Regex' }); + // this.actionTypeOptions.push({'id': FiltersAction.None, + // 'name': i18n('POPUPS_FILTER/SELECT_ACTION_NONE')}); + const modules = this.modules(); + if (modules) { + if (modules.includes('imap4flags')) { + this.allowMarkAsRead(true); + } + + if (modules.includes('fileinto')) { + this.actionTypeOptions.push({ + 'id': FiltersAction.MoveTo, + 'name': i18n('POPUPS_FILTER/SELECT_ACTION_MOVE_TO') + }); + this.actionTypeOptions.push({ + 'id': FiltersAction.Forward, + 'name': i18n('POPUPS_FILTER/SELECT_ACTION_FORWARD_TO') + }); + } + + if (modules.includes('reject')) { + this.actionTypeOptions.push({ 'id': FiltersAction.Reject, 'name': i18n('POPUPS_FILTER/SELECT_ACTION_REJECT') }); + } + + if (modules.includes('vacation')) { + this.actionTypeOptions.push({ + 'id': FiltersAction.Vacation, + 'name': i18n('POPUPS_FILTER/SELECT_ACTION_VACATION_MESSAGE') + }); + } + + if (modules.includes('body')) { + this.fieldOptions.push({ 'id': FilterConditionField.Body, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_BODY') }); + } + + if (modules.includes('regex')) { + this.typeOptions.push({ 'id': FilterConditionType.Regex, 'name': 'Regex' }); + } } + this.actionTypeOptions.push({ 'id': FiltersAction.Discard, 'name': i18n('POPUPS_FILTER/SELECT_ACTION_DISCARD') }); + this.typeOptionsSize([ { 'id': FilterConditionType.Over, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_OVER') }, { 'id': FilterConditionType.Under, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_UNDER') } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Filters/SieveStorage.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Filters/SieveStorage.php index f68257078..29bad1452 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Filters/SieveStorage.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Filters/SieveStorage.php @@ -41,61 +41,53 @@ class SieveStorage implements FiltersInterface public function Load(\RainLoop\Model\Account $oAccount, bool $bAllowRaw = false) : array { - $sRaw = ''; - - $bBasicIsActive = false; - $bRawIsActive = false; - $aModules = array(); $aFilters = array(); + $aScripts = array(); $oSieveClient = new \MailSo\Sieve\ManageSieveClient(); $oSieveClient->SetLogger($this->oLogger); $oSieveClient->SetTimeOuts(10, (int) $this->oConfig->Get('labs', 'sieve_timeout', 10)); - if ($oAccount->SieveConnectAndLoginHelper($this->oPlugins, $oSieveClient, $this->oConfig)) - { + if ($oAccount->SieveConnectAndLoginHelper($this->oPlugins, $oSieveClient, $this->oConfig)) { $aModules = $oSieveClient->Modules(); $aList = $oSieveClient->ListScripts(); - if (0 < \count($aList)) - { - if (isset($aList[self::SIEVE_FILE_NAME])) - { - $bBasicIsActive = !!$aList[self::SIEVE_FILE_NAME]; - $sS = $oSieveClient->GetScript(self::SIEVE_FILE_NAME); - if ($sS) - { - $aFilters = $this->fileStringToCollection($sS); - } + if (!empty($aList[self::SIEVE_FILE_NAME])) { + $sS = $oSieveClient->GetScript(self::SIEVE_FILE_NAME); + if ($sS) { + $aFilters = $this->fileStringToCollection($sS); } + } - if ($bAllowRaw && isset($aList[self::SIEVE_FILE_NAME_RAW])) - { - $bRawIsActive = !!$aList[self::SIEVE_FILE_NAME_RAW]; - $sRaw = \trim($oSieveClient->GetScript(self::SIEVE_FILE_NAME_RAW)); + if ($bAllowRaw) { + foreach ($aList as $name => $active) { + if ($name != self::SIEVE_FILE_NAME) { + $aScripts[$name] = array( + 'name' => $name, + 'active' => $active, + 'body' => $oSieveClient->GetScript($name) // \trim() ? + ); + } } } $oSieveClient->LogoutAndDisconnect(); } + if (!isset($aList[self::SIEVE_FILE_NAME_RAW])) { + $aScripts[$name] = array( + 'name' => self::SIEVE_FILE_NAME_RAW, + 'active' => false, + 'body' => '' + ); + } + return array( 'RawIsAllow' => $bAllowRaw, - 'RawIsActive' => $bRawIsActive, - 'Raw' => $bAllowRaw ? $sRaw : '', - 'Filters' => !$bBasicIsActive && !$bRawIsActive ? array() : $aFilters, - 'Capa' => $bAllowRaw ? $aModules : array(), - 'Modules' => array( - 'redirect' => \in_array('fileinto', $aModules), - 'regex' => \in_array('regex', $aModules), - 'relational' => \in_array('relational', $aModules), - 'date' => \in_array('date', $aModules), - 'moveto' => \in_array('fileinto', $aModules), - 'reject' => \in_array('reject', $aModules), - 'vacation' => \in_array('vacation', $aModules), - 'markasread' => \in_array('imap4flags', $aModules) - ) + 'Filters' => $aFilters, + 'Capa' => $aModules, + 'Scripts' => $aScripts ); }