mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-01 04:22:15 +08:00
Prepare Sieve Filtering feature for advanced editing/handling
This commit is contained in:
parent
4e1722560f
commit
e023a5d6ab
4 changed files with 72 additions and 81 deletions
|
@ -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([]);
|
||||
|
|
|
@ -4,7 +4,7 @@ class FilterUserStore {
|
|||
constructor() {
|
||||
ko.addObservablesTo(this, {
|
||||
capa: '',
|
||||
modules: {},
|
||||
modules: [],
|
||||
raw: ''
|
||||
});
|
||||
|
||||
|
|
|
@ -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') }
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue