diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index 803809b94..b17dba8f6 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -477,16 +477,15 @@ class rcube_sieve_engine // Initialize the form $rules = rcube_utils::get_input_value('r', rcube_utils::INPUT_GET); if (!empty($rules)) { - $i = 0; + $tests = array(); foreach ($rules as $rule) { list($header, $value) = explode(':', $rule, 2); - $tests[$i] = array( + $tests[] = array( 'type' => 'contains', 'test' => 'header', 'arg1' => $header, 'arg2' => $value, ); - $i++; } $this->form = array( @@ -757,7 +756,7 @@ class rcube_sieve_engine $this->form['tests'][$i]['arg'] = $target; if ($type != 'exists') { - if (!count($target)) { + if (empty($target)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); } else if (strpos($type, 'count-') === 0) { @@ -774,7 +773,7 @@ class rcube_sieve_engine } } - if (!preg_match('/^(regex|matches|count-)/', $type) && count($target)) { + if (!preg_match('/^(regex|matches|count-)/', $type) && !empty($target)) { foreach ($target as $arg) { if (!$this->validate_date_part($datepart, $arg)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat'); @@ -817,7 +816,7 @@ class rcube_sieve_engine $this->form['tests'][$i]['header'] = $dateheader; if ($type != 'exists') { - if (!count($target)) { + if (empty($target)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty'); } else if (strpos($type, 'count-') === 0) { @@ -834,7 +833,7 @@ class rcube_sieve_engine } } - if (count($target) && !preg_match('/^(regex|matches|count-)/', $type)) { + if (!empty($target) && !preg_match('/^(regex|matches|count-)/', $type)) { foreach ($target as $arg) { if (!$this->validate_date_part($datepart, $arg)) { $this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat'); @@ -1452,7 +1451,7 @@ class rcube_sieve_engine // 'any' flag if ((!isset($this->form) && empty($scr['tests']) && !empty($scr)) - || (count($scr['tests']) == 1 && $scr['tests'][0]['test'] == 'true' && !$scr['tests'][0]['not']) + || (is_array($scr['tests']) && count($scr['tests']) == 1 && $scr['tests'][0]['test'] == 'true' && !$scr['tests'][0]['not']) ) { $any = true; } @@ -1587,8 +1586,17 @@ class rcube_sieve_engine function rule_div($fid, $id, $div = true, $compact = false) { - $rule = isset($this->form) ? $this->form['tests'][$id] : $this->script[$fid]['tests'][$id]; - $rows_num = isset($this->form) ? count($this->form['tests']) : count($this->script[$fid]['tests']); + $rule = isset($this->form) ? $this->form['tests'][$id] : $this->script[$fid]['tests'][$id]; + + if (isset($this->form['tests'])) { + $rows_num = count($this->form['tests']); + } + else if (isset($this->script[$fid]['tests'])) { + $rows_num = count($this->script[$fid]['tests']); + } + else { + $rows_num = 0; + } // headers select $select_header = new html_select(array('name' => "_header[]", 'id' => 'header'.$id, @@ -2003,8 +2011,17 @@ class rcube_sieve_engine function action_div($fid, $id, $div=true) { - $action = isset($this->form) ? $this->form['actions'][$id] : $this->script[$fid]['actions'][$id]; - $rows_num = isset($this->form) ? count($this->form['actions']) : count($this->script[$fid]['actions']); + $action = isset($this->form) ? $this->form['actions'][$id] : $this->script[$fid]['actions'][$id]; + + if (isset($this->form['actions'])) { + $rows_num = count($this->form['actions']); + } + else if (isset($this->script[$fid]['actions'])) { + $rows_num = count($this->script[$fid]['actions']); + } + else { + $rows_num = 0; + } $out = $div ? '