summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2015-02-18 07:30:48 -0500
committerAleksander Machniak <alec@alec.pl>2015-02-18 07:30:48 -0500
commit3e0ad293e118a078d227ca15aaab7cf6cbdb0851 (patch)
tree6a6a51887d014942c1bf4f9f3085cc7e98252db6 /plugins
parent701ef30c28a9db9a1ec905d3911a1fa346d1d010 (diff)
Fix PHP fatal error when visiting Vacation interface and there's no sieve script yet
Diffstat (limited to 'plugins')
-rw-r--r--plugins/managesieve/Changelog2
-rw-r--r--plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php6
-rw-r--r--plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php94
3 files changed, 58 insertions, 44 deletions
diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog
index 5255d5b6b..8ce63c811 100644
--- a/plugins/managesieve/Changelog
+++ b/plugins/managesieve/Changelog
@@ -1,3 +1,5 @@
+- Fix PHP fatal error when visiting Vacation interface and there's no sieve script yet
+
* version 8.2 [2015-01-14]
-----------------------------------------------------------
- Fix bug where actions without if/elseif/else in sieve scripts were skipped
diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
index d412e17db..69ae4b8a6 100644
--- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
+++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
@@ -2344,12 +2344,12 @@ class rcube_sieve_engine
*/
protected function init_script()
{
- $this->script = $this->sieve->script->as_array();
-
- if (!$this->script) {
+ if (!$this->sieve->script) {
return;
}
+ $this->script = $this->sieve->script->as_array();
+
$headers = array();
$exceptions = array('date', 'currentdate', 'size', 'body');
diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php
index 28fd80125..8d865008f 100644
--- a/plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php
+++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php
@@ -562,62 +562,74 @@ class rcube_sieve_vacation extends rcube_sieve_engine
$this->script_name = 'roundcube';
}
- $this->script = array($rule);
- $script_active = false;
+ // use default script contents
+ if (!$this->rc->config->get('managesieve_kolab_master')) {
+ $script_file = $this->rc->config->get('managesieve_default');
+ if ($script_file && is_readable($script_file)) {
+ $content = file_get_contents($script_file);
+ }
+ }
+
+ // create and load script
+ if ($this->sieve->save_script($this->script_name, $content)) {
+ $this->sieve->load($this->script_name);
+ }
}
- // if script exists
- else {
- $script_active = in_array($this->script_name, $this->active);
- // re-order rules if needed
- if (isset($rule['after']) && $rule['after'] !== '') {
- // reset original vacation rule
- if (isset($this->vacation['idx'])) {
- $this->script[$this->vacation['idx']] = null;
- }
+ $script_active = in_array($this->script_name, $this->active);
- // add at target position
- if ($rule['after'] >= count($this->script) - 1) {
- $this->script[] = $rule;
- }
- else {
- $script = array();
+ // re-order rules if needed
+ if (isset($rule['after']) && $rule['after'] !== '') {
+ // reset original vacation rule
+ if (isset($this->vacation['idx'])) {
+ $this->script[$this->vacation['idx']] = null;
+ }
- foreach ($this->script as $idx => $r) {
- if ($r) {
- $script[] = $r;
- }
+ // add at target position
+ if ($rule['after'] >= count($this->script) - 1) {
+ $this->script[] = $rule;
+ }
+ else {
+ $script = array();
- if ($idx == $rule['after']) {
- $script[] = $rule;
- }
+ foreach ($this->script as $idx => $r) {
+ if ($r) {
+ $script[] = $r;
}
- $this->script = $script;
+ if ($idx == $rule['after']) {
+ $script[] = $rule;
+ }
}
- $this->script = array_values(array_filter($this->script));
- }
- // update original vacation rule if it exists
- else if (isset($this->vacation['idx'])) {
- $this->script[$this->vacation['idx']] = $rule;
- }
- // otherwise put vacation rule on top
- else {
- array_unshift($this->script, $rule);
+ $this->script = $script;
}
- // if the script was not active, we need to de-activate
- // all rules except the vacation rule, but only if it is not disabled
- if (!$script_active && !$rule['disabled']) {
- foreach ($this->script as $idx => $r) {
- if (empty($r['actions']) || $r['actions'][0]['type'] != 'vacation') {
- $this->script[$idx]['disabled'] = true;
- }
+ $this->script = array_values(array_filter($this->script));
+ }
+ // update original vacation rule if it exists
+ else if (isset($this->vacation['idx'])) {
+ $this->script[$this->vacation['idx']] = $rule;
+ }
+ // otherwise put vacation rule on top
+ else {
+ array_unshift($this->script, $rule);
+ }
+
+ // if the script was not active, we need to de-activate
+ // all rules except the vacation rule, but only if it is not disabled
+ if (!$script_active && !$rule['disabled']) {
+ foreach ($this->script as $idx => $r) {
+ if (empty($r['actions']) || $r['actions'][0]['type'] != 'vacation') {
+ $this->script[$idx]['disabled'] = true;
}
}
}
+ if (!$this->sieve->script) {
+ return false;
+ }
+
$this->sieve->script->content = $this->script;
// save the script