From b59b72cc3028cc0514e951f135d8bfe7efcaaa6f Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 26 Feb 2015 18:04:03 +0100 Subject: Fix "Non-static method PEAR::isError() should not be called statically" errors (#1490281) --- plugins/managesieve/lib/Roundcube/rcube_sieve.php | 93 +++++++++++++++------- .../lib/Roundcube/rcube_sieve_engine.php | 5 +- 2 files changed, 68 insertions(+), 30 deletions(-) (limited to 'plugins/managesieve') diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve.php b/plugins/managesieve/lib/Roundcube/rcube_sieve.php index 389c85012..59a7bc134 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve.php @@ -68,7 +68,9 @@ class rcube_sieve $this->sieve->setDebug(true, array($this, 'debug_handler')); } - if (PEAR::isError($this->sieve->connect($host, $port, $options, $usetls))) { + $result = $this->sieve->connect($host, $port, $options, $usetls); + + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_CONNECTION); } @@ -78,9 +80,9 @@ class rcube_sieve $password = $auth_pw; } - if (PEAR::isError($this->sieve->login($username, $password, - $auth_type ? strtoupper($auth_type) : null, $authz)) - ) { + $result = $this->sieve->login($username, $password, $auth_type ? strtoupper($auth_type) : null, $authz); + + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_LOGIN); } @@ -115,22 +117,28 @@ class rcube_sieve */ public function save($name = null) { - if (!$this->sieve) + if (!$this->sieve) { return $this->_set_error(self::ERROR_INTERNAL); + } - if (!$this->script) + if (!$this->script) { return $this->_set_error(self::ERROR_INTERNAL); + } - if (!$name) + if (!$name) { $name = $this->current; + } $script = $this->script->as_text(); - if (!$script) + if (!$script) { $script = '/* empty script */'; + } - if (PEAR::isError($this->sieve->installScript($name, $script))) + $result = $this->sieve->installScript($name, $script); + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_INSTALL); + } return true; } @@ -140,14 +148,19 @@ class rcube_sieve */ public function save_script($name, $content = null) { - if (!$this->sieve) + if (!$this->sieve) { return $this->_set_error(self::ERROR_INTERNAL); + } - if (!$content) + if (!$content) { $content = '/* empty script */'; + } + + $result = $this->sieve->installScript($name, $content); - if (PEAR::isError($this->sieve->installScript($name, $content))) + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_INSTALL); + } return true; } @@ -157,14 +170,19 @@ class rcube_sieve */ public function activate($name = null) { - if (!$this->sieve) + if (!$this->sieve) { return $this->_set_error(self::ERROR_INTERNAL); + } - if (!$name) + if (!$name) { $name = $this->current; + } - if (PEAR::isError($this->sieve->setActive($name))) + $result = $this->sieve->setActive($name); + + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_ACTIVATE); + } return true; } @@ -174,11 +192,15 @@ class rcube_sieve */ public function deactivate() { - if (!$this->sieve) + if (!$this->sieve) { return $this->_set_error(self::ERROR_INTERNAL); + } + + $result = $this->sieve->setActive(''); - if (PEAR::isError($this->sieve->setActive(''))) + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_DEACTIVATE); + } return true; } @@ -188,22 +210,32 @@ class rcube_sieve */ public function remove($name = null) { - if (!$this->sieve) + if (!$this->sieve) { return $this->_set_error(self::ERROR_INTERNAL); + } - if (!$name) + if (!$name) { $name = $this->current; + } // script must be deactivated first - if ($name == $this->sieve->getActive()) - if (PEAR::isError($this->sieve->setActive(''))) + if ($name == $this->sieve->getActive()) { + $result = $this->sieve->setActive(''); + + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_DELETE); + } + } + + $result = $this->sieve->removeScript($name); - if (PEAR::isError($this->sieve->removeScript($name))) + if (is_a($result, 'PEAR_Error')) { return $this->_set_error(self::ERROR_DELETE); + } - if ($name == $this->current) + if ($name == $this->current) { $this->current = null; + } return true; } @@ -221,7 +253,7 @@ class rcube_sieve $ext = $this->sieve->getExtensions(); - if (PEAR::isError($ext)) { + if (is_a($ext, 'PEAR_Error')) { return array(); } @@ -250,8 +282,9 @@ class rcube_sieve $list = $this->sieve->listScripts(); - if (PEAR::isError($list)) + if (is_a($list, 'PEAR_Error')) { return $this->_set_error(self::ERROR_OTHER); + } $this->list = $list; } @@ -283,8 +316,9 @@ class rcube_sieve $script = $this->sieve->getScript($name); - if (PEAR::isError($script)) + if (is_a($script, 'PEAR_Error')) { return $this->_set_error(self::ERROR_OTHER); + } // try to parse from Roundcube format $this->script = $this->_parse($script); @@ -349,8 +383,9 @@ class rcube_sieve $content = $this->sieve->getScript($name); - if (PEAR::isError($content)) + if (is_a($content, 'PEAR_Error')) { return $this->_set_error(self::ERROR_OTHER); + } return $content; } @@ -366,10 +401,12 @@ class rcube_sieve if ($copy) { $content = $this->sieve->getScript($copy); - if (PEAR::isError($content)) + if (is_a($content, 'PEAR_Error')) { return $this->_set_error(self::ERROR_OTHER); + } } + return $this->save_script($name, $content); } diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index 69ae4b8a6..98c4c952c 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -390,10 +390,11 @@ class rcube_sieve_engine } else if ($action == 'setget') { $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true); - $script = $this->sieve->get_script($script_name); + $script = $this->sieve->get_script($script_name); - if (PEAR::isError($script)) + if (is_a($script, 'PEAR_Error')) { exit; + } $browser = new rcube_browser; -- cgit v1.2.3 From 05b11f7ef0dd100110ee728770e3fa157b994ed0 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 12 Mar 2015 06:31:22 -0400 Subject: Fix handling of header test with one-element array as header name --- plugins/managesieve/Changelog | 3 +++ plugins/managesieve/composer.json | 2 +- .../lib/Roundcube/rcube_sieve_engine.php | 28 ++++++++++++---------- 3 files changed, 19 insertions(+), 14 deletions(-) (limited to 'plugins/managesieve') diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog index 8ce63c811..9291d550b 100644 --- a/plugins/managesieve/Changelog +++ b/plugins/managesieve/Changelog @@ -1,4 +1,7 @@ +* version 8.3 [2015-03-12] +----------------------------------------------------------- - Fix PHP fatal error when visiting Vacation interface and there's no sieve script yet +- Fix handling of header test with one-element array as header name * version 8.2 [2015-01-14] ----------------------------------------------------------- diff --git a/plugins/managesieve/composer.json b/plugins/managesieve/composer.json index 6d640da08..529167f23 100644 --- a/plugins/managesieve/composer.json +++ b/plugins/managesieve/composer.json @@ -3,7 +3,7 @@ "type": "roundcube-plugin", "description": "Adds a possibility to manage Sieve scripts (incoming mail filters). It's clickable interface which operates on text scripts and communicates with server using managesieve protocol. Adds Filters tab in Settings.", "license": "GPLv3+", - "version": "8.2", + "version": "8.3", "authors": [ { "name": "Aleksander Machniak", diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index 98c4c952c..2f2791d30 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -63,7 +63,7 @@ class rcube_sieve_engine 1 => 'notifyimportancehigh' ); - const VERSION = '8.2'; + const VERSION = '8.3'; const PROGNAME = 'Roundcube (Managesieve)'; const PORT = 4190; @@ -1394,19 +1394,21 @@ class rcube_sieve_engine } if (isset($rule['test'])) { - if (in_array($rule['test'], array('header', 'address', 'envelope')) - && !is_array($rule['arg1']) - && ($header = strtolower($rule['arg1'])) - && isset($this->headers[$header]) - ) { - $test = $header; + if (in_array($rule['test'], array('header', 'address', 'envelope'))) { + if (is_array($rule['arg1']) && count($rule['arg1']) == 1) { + $rule['arg1'] = $rule['arg1'][0]; + } + + $matches = ($header = strtolower($rule['arg1'])) && isset($this->headers[$header]); + $test = $matches ? $header : '...'; } - else if ($rule['test'] == 'exists' - && !is_array($rule['arg']) - && ($header = strtolower($rule['arg'])) - && isset($this->headers[$header]) - ) { - $test = $header; + else if ($rule['test'] == 'exists') { + if (is_array($rule['arg']) && count($rule['arg']) == 1) { + $rule['arg'] = $rule['arg'][0]; + } + + $matches = ($header = strtolower($rule['arg'])) && isset($this->headers[$header]); + $test = $matches ? $header : '...'; } else if (in_array($rule['test'], array('size', 'body', 'date', 'currentdate'))) { $test = $rule['test']; -- cgit v1.2.3 From e4338fdf384f040101be3fad507c16ecb229580a Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 13 Mar 2015 08:46:25 +0100 Subject: Fix missing host:port in connection error message --- plugins/managesieve/Changelog | 1 + plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'plugins/managesieve') diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog index 9291d550b..0aa48d2d2 100644 --- a/plugins/managesieve/Changelog +++ b/plugins/managesieve/Changelog @@ -2,6 +2,7 @@ ----------------------------------------------------------- - Fix PHP fatal error when visiting Vacation interface and there's no sieve script yet - Fix handling of header test with one-element array as header name +- Fix missing host:port in connection error message * version 8.2 [2015-01-14] ----------------------------------------------------------- diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index 2f2791d30..282ffa943 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -122,9 +122,6 @@ class rcube_sieve_engine case rcube_sieve::ERROR_CONNECTION: case rcube_sieve::ERROR_LOGIN: $this->rc->output->show_message('managesieve.filterconnerror', 'error'); - rcube::raise_error(array('code' => 403, 'type' => 'php', - 'file' => __FILE__, 'line' => __LINE__, - 'message' => "Unable to connect to managesieve on $host:$port"), true, false); break; default: @@ -210,7 +207,18 @@ class rcube_sieve_engine $plugin['socket_options'] ); - return $this->sieve->error(); + $error = $this->sieve->error(); + + if ($error) { + rcube::raise_error(array( + 'code' => 403, + 'file' => __FILE__, + 'line' => __LINE__, + 'message' => "Unable to connect to managesieve on $host:$port" + ), true, false); + } + + return $error; } /** -- cgit v1.2.3 From fa857716e66f73f979e4a798a8c4e91c7612a7d1 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 14 Apr 2015 05:24:43 -0400 Subject: Add option to define default vacation interval --- plugins/managesieve/Changelog | 2 ++ plugins/managesieve/config.inc.php.dist | 5 ++++ .../lib/Roundcube/rcube_sieve_engine.php | 2 +- .../lib/Roundcube/rcube_sieve_vacation.php | 32 +++++++++++++++++++++- 4 files changed, 39 insertions(+), 2 deletions(-) (limited to 'plugins/managesieve') diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog index 0aa48d2d2..dba0be2c1 100644 --- a/plugins/managesieve/Changelog +++ b/plugins/managesieve/Changelog @@ -1,3 +1,5 @@ +- Add option to define default vacation interval + * version 8.3 [2015-03-12] ----------------------------------------------------------- - Fix PHP fatal error when visiting Vacation interface and there's no sieve script yet diff --git a/plugins/managesieve/config.inc.php.dist b/plugins/managesieve/config.inc.php.dist index b9f9a50bd..08b98288c 100644 --- a/plugins/managesieve/config.inc.php.dist +++ b/plugins/managesieve/config.inc.php.dist @@ -86,5 +86,10 @@ $config['managesieve_domains'] = array(); // 2 - add Vacation section, but hide Filters section $config['managesieve_vacation'] = 0; +// Default vacation interval (in days). +// Note: If server supports vacation-seconds extension it is possible +// to define interval in seconds here (as a string), e.g. "3600s". +$config['managesieve_vacation_interval'] = 0; + // Supported methods of notify extension. Default: 'mailto' $config['managesieve_notify_methods'] = array('mailto'); diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php index 282ffa943..b8af0373d 100644 --- a/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php +++ b/plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @@ -1784,7 +1784,7 @@ class rcube_sieve_engine $this->error_class($id, 'action', 'addresses', 'action_addresses'), 30); $out .= '
' . rcube::Q($this->plugin->gettext($vsec ? 'vacationinterval' : 'vacationdays')) . '
' .'error_class($id, 'action', 'interval', 'action_interval') .' />'; if ($vsec) { $out .= '