Prepare Sieve Filtering feature for advanced editing/handling

This commit is contained in:
djmaze 2021-01-06 01:06:16 +01:00
parent 4e1722560f
commit e023a5d6ab
4 changed files with 72 additions and 81 deletions

View file

@ -103,11 +103,11 @@ class FiltersUserSettings {
data.Result.Filters.map(aItem => FilterModel.reviveFromJson(aItem)).filter(v => v) 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(data.Result.Scripts['rainloop.user.raw'].body);
this.filterRaw.capa(Array.isArray(data.Result.Capa) ? data.Result.Capa.join(' ') : ''); this.filterRaw.capa(data.Result.Capa.join(' '));
this.filterRaw.active(!!data.Result.RawIsActive); this.filterRaw.active(data.Result.Scripts['rainloop.user.raw'].active);
this.filterRaw.allow(!!data.Result.RawIsAllow); this.filterRaw.allow(!!data.Result.RawIsAllow);
} else { } else {
this.filters([]); this.filters([]);

View file

@ -4,7 +4,7 @@ class FilterUserStore {
constructor() { constructor() {
ko.addObservablesTo(this, { ko.addObservablesTo(this, {
capa: '', capa: '',
modules: {}, modules: [],
raw: '' raw: ''
}); });

View file

@ -67,50 +67,12 @@ class FilterPopupView extends AbstractViewNext {
populateOptions() { populateOptions() {
this.actionTypeOptions([]); 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([ this.fieldOptions([
{ 'id': FilterConditionField.From, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_FROM') }, { 'id': FilterConditionField.From, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_FROM') },
{ 'id': FilterConditionField.Recipient, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_RECIPIENTS') }, { 'id': FilterConditionField.Recipient, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_RECIPIENTS') },
{ 'id': FilterConditionField.Subject, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_SUBJECT') }, { 'id': FilterConditionField.Subject, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_SUBJECT') },
{ 'id': FilterConditionField.Size, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_SIZE') }, { 'id': FilterConditionField.Size, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_SIZE') },
{ 'id': FilterConditionField.Header, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_HEADER') }, { 'id': FilterConditionField.Header, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_HEADER') }
{ 'id': FilterConditionField.Body, 'name': i18n('POPUPS_FILTER/SELECT_FIELD_BODY') }
]); ]);
this.typeOptions([ this.typeOptions([
@ -120,10 +82,47 @@ class FilterPopupView extends AbstractViewNext {
{ 'id': FilterConditionType.NotEqualTo, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_NOT_EQUAL_TO') } { 'id': FilterConditionType.NotEqualTo, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_NOT_EQUAL_TO') }
]); ]);
if (modules && modules.regex) { // this.actionTypeOptions.push({'id': FiltersAction.None,
this.typeOptions.push({ 'id': FilterConditionType.Regex, 'name': 'Regex' }); // '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([ this.typeOptionsSize([
{ 'id': FilterConditionType.Over, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_OVER') }, { 'id': FilterConditionType.Over, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_OVER') },
{ 'id': FilterConditionType.Under, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_UNDER') } { 'id': FilterConditionType.Under, 'name': i18n('POPUPS_FILTER/SELECT_TYPE_UNDER') }

View file

@ -41,61 +41,53 @@ class SieveStorage implements FiltersInterface
public function Load(\RainLoop\Model\Account $oAccount, bool $bAllowRaw = false) : array public function Load(\RainLoop\Model\Account $oAccount, bool $bAllowRaw = false) : array
{ {
$sRaw = '';
$bBasicIsActive = false;
$bRawIsActive = false;
$aModules = array(); $aModules = array();
$aFilters = array(); $aFilters = array();
$aScripts = array();
$oSieveClient = new \MailSo\Sieve\ManageSieveClient(); $oSieveClient = new \MailSo\Sieve\ManageSieveClient();
$oSieveClient->SetLogger($this->oLogger); $oSieveClient->SetLogger($this->oLogger);
$oSieveClient->SetTimeOuts(10, (int) $this->oConfig->Get('labs', 'sieve_timeout', 10)); $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(); $aModules = $oSieveClient->Modules();
$aList = $oSieveClient->ListScripts(); $aList = $oSieveClient->ListScripts();
if (0 < \count($aList)) if (!empty($aList[self::SIEVE_FILE_NAME])) {
{ $sS = $oSieveClient->GetScript(self::SIEVE_FILE_NAME);
if (isset($aList[self::SIEVE_FILE_NAME])) if ($sS) {
{ $aFilters = $this->fileStringToCollection($sS);
$bBasicIsActive = !!$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])) if ($bAllowRaw) {
{ foreach ($aList as $name => $active) {
$bRawIsActive = !!$aList[self::SIEVE_FILE_NAME_RAW]; if ($name != self::SIEVE_FILE_NAME) {
$sRaw = \trim($oSieveClient->GetScript(self::SIEVE_FILE_NAME_RAW)); $aScripts[$name] = array(
'name' => $name,
'active' => $active,
'body' => $oSieveClient->GetScript($name) // \trim() ?
);
}
} }
} }
$oSieveClient->LogoutAndDisconnect(); $oSieveClient->LogoutAndDisconnect();
} }
if (!isset($aList[self::SIEVE_FILE_NAME_RAW])) {
$aScripts[$name] = array(
'name' => self::SIEVE_FILE_NAME_RAW,
'active' => false,
'body' => ''
);
}
return array( return array(
'RawIsAllow' => $bAllowRaw, 'RawIsAllow' => $bAllowRaw,
'RawIsActive' => $bRawIsActive, 'Filters' => $aFilters,
'Raw' => $bAllowRaw ? $sRaw : '', 'Capa' => $aModules,
'Filters' => !$bBasicIsActive && !$bRawIsActive ? array() : $aFilters, 'Scripts' => $aScripts
'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)
)
); );
} }