summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authoralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-10-19 09:15:34 +0000
committeralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-10-19 09:15:34 +0000
commit9a0829ca596aba42c3e8fd2e9fba79c9b0546c20 (patch)
tree0cb798b77f62de87ba23a6df77d187ef33793cef /plugins
parent97de73fe557a248ad14c8aef6ba90e78cd9efed1 (diff)
- Fixed sorting of scripts, scripts including aware of the sort order
git-svn-id: https://svn.roundcube.net/trunk@5348 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/managesieve/Changelog2
-rw-r--r--plugins/managesieve/managesieve.js8
-rw-r--r--plugins/managesieve/managesieve.php71
3 files changed, 67 insertions, 14 deletions
diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog
index 16f60784a..185510410 100644
--- a/plugins/managesieve/Changelog
+++ b/plugins/managesieve/Changelog
@@ -1,3 +1,5 @@
+- Fixed sorting of scripts, scripts including aware of the sort order
+
* version 5.0-beta [2011-10-17]
-----------------------------------------------------------
- Added possibility to create a filter based on selected message "in-place"
diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js
index be2d54891..5f9c67004 100644
--- a/plugins/managesieve/managesieve.js
+++ b/plugins/managesieve/managesieve.js
@@ -341,6 +341,14 @@ rcube_webmail.prototype.managesieve_updatelist = function(action, o)
this.env.filtersets[id] = o.name;
list.insert_row(row.get(0));
+
+ // move row into its position on the list
+ if (o.index != list.rowcount-1) {
+ row.detach();
+ var elem = $('tr:visible', list.list).get(o.index);
+ row.insertBefore(elem);
+ }
+
list.select(id);
break;
diff --git a/plugins/managesieve/managesieve.php b/plugins/managesieve/managesieve.php
index c778ef57f..0787c7642 100644
--- a/plugins/managesieve/managesieve.php
+++ b/plugins/managesieve/managesieve.php
@@ -372,7 +372,7 @@ class managesieve extends rcube_plugin
}
}
else if ($action == 'setact' && !$error) {
- $script_name = get_input_value('_set', RCUBE_INPUT_GPC);
+ $script_name = get_input_value('_set', RCUBE_INPUT_GPC, true);
$result = $this->activate_script($script_name);
$kep14 = $this->rc->config->get('managesieve_kolab_master');
@@ -386,7 +386,7 @@ class managesieve extends rcube_plugin
}
}
else if ($action == 'deact' && !$error) {
- $script_name = get_input_value('_set', RCUBE_INPUT_GPC);
+ $script_name = get_input_value('_set', RCUBE_INPUT_GPC, true);
$result = $this->deactivate_script($script_name);
if ($result === true) {
@@ -399,7 +399,7 @@ class managesieve extends rcube_plugin
}
}
else if ($action == 'setdel' && !$error) {
- $script_name = get_input_value('_set', RCUBE_INPUT_GPC);
+ $script_name = get_input_value('_set', RCUBE_INPUT_GPC, true);
$result = $this->remove_script($script_name);
if ($result === true) {
@@ -412,7 +412,7 @@ class managesieve extends rcube_plugin
}
}
else if ($action == 'setget') {
- $script_name = get_input_value('_set', RCUBE_INPUT_GPC);
+ $script_name = get_input_value('_set', RCUBE_INPUT_GPC, true);
$script = $this->sieve->get_script($script_name);
if (PEAR::isError($script))
@@ -512,9 +512,10 @@ class managesieve extends rcube_plugin
$exceptions = $this->rc->config->get('managesieve_filename_exceptions');
$kolab = $this->rc->config->get('managesieve_kolab_master');
$name_uc = mb_strtolower($name);
+ $list = $this->list_scripts();
if (!$name) {
- $this->errors['name'] = $this->gettext('emptyname');
+ $this->errors['name'] = $this->gettext('cannotbeempty');
}
else if (mb_strlen($name) > 128) {
$this->errors['name'] = $this->gettext('nametoolong');
@@ -525,7 +526,7 @@ class managesieve extends rcube_plugin
else if (!empty($kolab) && in_array($name_uc, array('MASTER', 'USER', 'MANAGEMENT'))) {
$this->errors['name'] = $this->gettext('namereserved');
}
- else if (($list = $this->list_scripts()) && in_array($name, $list)) {
+ else if (in_array($name, $list)) {
$this->errors['name'] = $this->gettext('setexist');
}
else if ($from == 'file') {
@@ -558,9 +559,15 @@ class managesieve extends rcube_plugin
}
if (!$error && empty($this->errors)) {
+ // Find position of the new script on the list
+ $list[] = $name;
+ asort($list, SORT_LOCALE_STRING);
+ $list = array_values($list);
+ $index = array_search($name, $list);
+
$this->rc->output->show_message('managesieve.setcreated', 'confirmation');
$this->rc->output->command('parent.managesieve_updatelist', 'setadd',
- array('name' => $name));
+ array('name' => $name, 'index' => $index));
} else if ($msg) {
$this->rc->output->command('display_message', $msg, 'error');
} else if ($error) {
@@ -881,9 +888,9 @@ class managesieve extends rcube_plugin
$list = $this->list_scripts();
-// if ($list) {
-// asort($list, SORT_LOCALE_STRING);
-// }
+ if ($list) {
+ asort($list, SORT_LOCALE_STRING);
+ }
if (!empty($attrib['type']) && $attrib['type'] == 'list') {
// define list of cols to be displayed
@@ -976,7 +983,7 @@ class managesieve extends rcube_plugin
$select = new html_select(array('name' => '_copy', 'id' => '_copy'));
if (is_array($list)) {
-// asort($list, SORT_LOCALE_STRING);
+ asort($list, SORT_LOCALE_STRING);
if (!$copy)
$copy = $_SESSION['managesieve_current'];
@@ -1570,14 +1577,50 @@ class managesieve extends rcube_plugin
if ($user_script && ($key = array_search($name, $this->active)) === false) {
// ...rewrite USER file adding appropriate include command
if ($this->sieve->load($user_script)) {
- // @TODO: include order
- $this->sieve->script->add_rule(array(
+ $script = $this->sieve->script->as_array();
+ $list = array();
+ $regexp = '/' . preg_quote($extension, '/') . '$/';
+
+ // Create new include entry
+ $rule = array(
'actions' => array(
0 => array(
'target' => $name.$extension,
'type' => 'include',
'personal' => true,
- ))));
+ )));
+
+ // get all active scripts for sorting
+ foreach ($script as $rid => $rules) {
+ foreach ($rules['actions'] as $aid => $action) {
+ if ($action['type'] == 'include' && empty($action['global'])) {
+ $target = $extension ? preg_replace($regexp, '', $action['target']) : $action['target'];
+ $list[] = $target;
+ }
+ }
+ }
+ $list[] = $name;
+
+ // Sort and find current script position
+ asort($list, SORT_LOCALE_STRING);
+ $list = array_values($list);
+ $index = array_search($name, $list);
+
+ // add rule at the end of the script
+ if ($index === false || $index == count($list)-1) {
+ $this->sieve->script->add_rule($rule);
+ }
+ // add rule at index position
+ else {
+ $script2 = array();
+ foreach ($script as $rid => $rules) {
+ if ($rid == $index) {
+ $script2[] = $rule;
+ }
+ $script2[] = $rules;
+ }
+ $this->sieve->script->content = $script2;
+ }
$result = $this->sieve->save();
if ($result) {