summaryrefslogtreecommitdiff
path: root/plugins/managesieve/lib/Roundcube/rcube_sieve.php
diff options
context:
space:
mode:
authorCyrill von Wattenwyl <cvw@adfinis.com>2014-09-02 11:20:52 +0200
committerCyrill von Wattenwyl <cvw@adfinis.com>2014-09-02 11:20:52 +0200
commit11a40dd1fef6c5b78b054617caba4325f95ee386 (patch)
treede2e1d7efd6423ef4d1256dd5c90a972ad172719 /plugins/managesieve/lib/Roundcube/rcube_sieve.php
parent187fd666aa2f32dedfe544d69b7cb213698197f2 (diff)
parentba084313bfc9c7a5a83e0611fe4376543cc1653d (diff)
Merge branch 'master' of https://github.com/roundcube/roundcubemail
Conflicts: plugins/password/config.inc.php.dist
Diffstat (limited to 'plugins/managesieve/lib/Roundcube/rcube_sieve.php')
-rw-r--r--plugins/managesieve/lib/Roundcube/rcube_sieve.php81
1 files changed, 43 insertions, 38 deletions
diff --git a/plugins/managesieve/lib/Roundcube/rcube_sieve.php b/plugins/managesieve/lib/Roundcube/rcube_sieve.php
index 3bd2978da..389c85012 100644
--- a/plugins/managesieve/lib/Roundcube/rcube_sieve.php
+++ b/plugins/managesieve/lib/Roundcube/rcube_sieve.php
@@ -22,17 +22,6 @@
// Managesieve Protocol: RFC5804
-define('SIEVE_ERROR_CONNECTION', 1);
-define('SIEVE_ERROR_LOGIN', 2);
-define('SIEVE_ERROR_NOT_EXISTS', 3); // script not exists
-define('SIEVE_ERROR_INSTALL', 4); // script installation
-define('SIEVE_ERROR_ACTIVATE', 5); // script activation
-define('SIEVE_ERROR_DELETE', 6); // script deletion
-define('SIEVE_ERROR_INTERNAL', 7); // internal error
-define('SIEVE_ERROR_DEACTIVATE', 8); // script activation
-define('SIEVE_ERROR_OTHER', 255); // other/unknown error
-
-
class rcube_sieve
{
private $sieve; // Net_Sieve object
@@ -43,6 +32,16 @@ class rcube_sieve
public $current; // name of currently loaded script
private $exts; // array of supported extensions
+ const ERROR_CONNECTION = 1;
+ const ERROR_LOGIN = 2;
+ const ERROR_NOT_EXISTS = 3; // script not exists
+ const ERROR_INSTALL = 4; // script installation
+ const ERROR_ACTIVATE = 5; // script activation
+ const ERROR_DELETE = 6; // script deletion
+ const ERROR_INTERNAL = 7; // internal error
+ const ERROR_DEACTIVATE = 8; // script activation
+ const ERROR_OTHER = 255; // other/unknown error
+
/**
* Object constructor
@@ -57,10 +56,11 @@ class rcube_sieve
* @param boolean Enable/disable debugging
* @param string Proxy authentication identifier
* @param string Proxy authentication password
+ * @param array List of options to pass to stream_context_create().
*/
public function __construct($username, $password='', $host='localhost', $port=2000,
$auth_type=null, $usetls=true, $disabled=array(), $debug=false,
- $auth_cid=null, $auth_pw=null)
+ $auth_cid=null, $auth_pw=null, $options=array())
{
$this->sieve = new Net_Sieve();
@@ -68,8 +68,8 @@ class rcube_sieve
$this->sieve->setDebug(true, array($this, 'debug_handler'));
}
- if (PEAR::isError($this->sieve->connect($host, $port, null, $usetls))) {
- return $this->_set_error(SIEVE_ERROR_CONNECTION);
+ if (PEAR::isError($this->sieve->connect($host, $port, $options, $usetls))) {
+ return $this->_set_error(self::ERROR_CONNECTION);
}
if (!empty($auth_cid)) {
@@ -81,7 +81,7 @@ class rcube_sieve
if (PEAR::isError($this->sieve->login($username, $password,
$auth_type ? strtoupper($auth_type) : null, $authz))
) {
- return $this->_set_error(SIEVE_ERROR_LOGIN);
+ return $this->_set_error(self::ERROR_LOGIN);
}
$this->exts = $this->get_extensions();
@@ -116,10 +116,10 @@ class rcube_sieve
public function save($name = null)
{
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
if (!$this->script)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
if (!$name)
$name = $this->current;
@@ -130,7 +130,7 @@ class rcube_sieve
$script = '/* empty script */';
if (PEAR::isError($this->sieve->installScript($name, $script)))
- return $this->_set_error(SIEVE_ERROR_INSTALL);
+ return $this->_set_error(self::ERROR_INSTALL);
return true;
}
@@ -141,13 +141,13 @@ class rcube_sieve
public function save_script($name, $content = null)
{
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
if (!$content)
$content = '/* empty script */';
if (PEAR::isError($this->sieve->installScript($name, $content)))
- return $this->_set_error(SIEVE_ERROR_INSTALL);
+ return $this->_set_error(self::ERROR_INSTALL);
return true;
}
@@ -158,13 +158,13 @@ class rcube_sieve
public function activate($name = null)
{
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
if (!$name)
$name = $this->current;
if (PEAR::isError($this->sieve->setActive($name)))
- return $this->_set_error(SIEVE_ERROR_ACTIVATE);
+ return $this->_set_error(self::ERROR_ACTIVATE);
return true;
}
@@ -175,10 +175,10 @@ class rcube_sieve
public function deactivate()
{
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
if (PEAR::isError($this->sieve->setActive('')))
- return $this->_set_error(SIEVE_ERROR_DEACTIVATE);
+ return $this->_set_error(self::ERROR_DEACTIVATE);
return true;
}
@@ -189,7 +189,7 @@ class rcube_sieve
public function remove($name = null)
{
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
if (!$name)
$name = $this->current;
@@ -197,10 +197,10 @@ class rcube_sieve
// script must be deactivated first
if ($name == $this->sieve->getActive())
if (PEAR::isError($this->sieve->setActive('')))
- return $this->_set_error(SIEVE_ERROR_DELETE);
+ return $this->_set_error(self::ERROR_DELETE);
if (PEAR::isError($this->sieve->removeScript($name)))
- return $this->_set_error(SIEVE_ERROR_DELETE);
+ return $this->_set_error(self::ERROR_DELETE);
if ($name == $this->current)
$this->current = null;
@@ -217,9 +217,14 @@ class rcube_sieve
return $this->exts;
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
$ext = $this->sieve->getExtensions();
+
+ if (PEAR::isError($ext)) {
+ return array();
+ }
+
// we're working on lower-cased names
$ext = array_map('strtolower', (array) $ext);
@@ -241,12 +246,12 @@ class rcube_sieve
if (!$this->list) {
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
$list = $this->sieve->listScripts();
if (PEAR::isError($list))
- return $this->_set_error(SIEVE_ERROR_OTHER);
+ return $this->_set_error(self::ERROR_OTHER);
$this->list = $list;
}
@@ -260,7 +265,7 @@ class rcube_sieve
public function get_active()
{
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
return $this->sieve->getActive();
}
@@ -271,7 +276,7 @@ class rcube_sieve
public function load($name)
{
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
if ($this->current == $name)
return true;
@@ -279,7 +284,7 @@ class rcube_sieve
$script = $this->sieve->getScript($name);
if (PEAR::isError($script))
- return $this->_set_error(SIEVE_ERROR_OTHER);
+ return $this->_set_error(self::ERROR_OTHER);
// try to parse from Roundcube format
$this->script = $this->_parse($script);
@@ -295,7 +300,7 @@ class rcube_sieve
public function load_script($script)
{
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
// try to parse from Roundcube format
$this->script = $this->_parse($script);
@@ -340,12 +345,12 @@ class rcube_sieve
public function get_script($name)
{
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
$content = $this->sieve->getScript($name);
if (PEAR::isError($content))
- return $this->_set_error(SIEVE_ERROR_OTHER);
+ return $this->_set_error(self::ERROR_OTHER);
return $content;
}
@@ -356,13 +361,13 @@ class rcube_sieve
public function copy($name, $copy)
{
if (!$this->sieve)
- return $this->_set_error(SIEVE_ERROR_INTERNAL);
+ return $this->_set_error(self::ERROR_INTERNAL);
if ($copy) {
$content = $this->sieve->getScript($copy);
if (PEAR::isError($content))
- return $this->_set_error(SIEVE_ERROR_OTHER);
+ return $this->_set_error(self::ERROR_OTHER);
}
return $this->save_script($name, $content);