diff --git a/lib/Transport/Sieveconnect.php b/lib/Transport/Sieveconnect.php new file mode 100644 index 0000000..acc5426 --- /dev/null +++ b/lib/Transport/Sieveconnect.php @@ -0,0 +1,115 @@ + + * @category Horde + * @license http://www.horde.org/licenses/apache ASL + * @package Ingo + */ + +/** + * Ingo_Transport_Sieveconnect implements an Ingo transport driver to + * delegate ManageSieve connections to an external sieve-connect script + * + * @author Mike Cochrane + * @author Jan Schneider + * @category Horde + * @license http://www.horde.org/licenses/apache ASL + * @package Ingo + */ +class Ingo_Transport_Sieveconnect extends Ingo_Transport_Base +{ + /** + */ + protected $_supportShares = true; + + /** + * Constructor. + */ + public function __construct(array $params = array()) + { + parent::__construct(array_merge(array( + 'admin' => '', + 'debug' => false, + 'euser' => '', + 'hostspec' => 'localhost', + 'logintype' => 'PLAIN', + 'port' => 4190, + 'scriptname' => 'ingo', + 'usetls' => true, + 'script' => '/usr/bin/sieve-connect', + 'tmpdir' => $GLOBALS['conf']['tmpdir'] + ), $params)); + } + + /** + * Sets a script running on the backend. + * + * @param array $script The filter script information. Passed elements: + * - 'name': (string) the script name. + * - 'recipes': (array) the filter recipe objects. + * - 'script': (string) the filter script. + * + * @throws Ingo_Exception + */ + public function setScriptActive($script) + { + $scriptFile = $this->_params['tmpdir'] . '/transport' . md5($this->_params['username'] . $script['name']); + file_put_contents($scriptFile, $script['script']); + $cmd = sprintf("echo '%s' | %s -s %s -p %s -u %s --upload --localsieve %s --remotesieve %s ; echo '%s' | %s -s %s -p %s -u %s --activate --remotesieve %s", + $this->_params['password'], + $this->_params['script'], + $this->_params['hostspec'], + $this->_params['port'], + $this->_params['username'], + $scriptFile, + $script['name'], + $this->_params['password'], + $this->_params['script'], + $this->_params['hostspec'], + $this->_params['port'], + $this->_params['username'], + $script['name'] + ); + if (!empty($this->_params['debug'])) { + file_put_contents($scriptFile . 'debug', $cmd); + } + shell_exec($cmd); + unlink($scriptFile); + } + + /** + * Returns the content of the currently active script. + * + * @return array Keys 'name' (string) the active script, 'script' (string) The complete ruleset of the specified user. + * @throws Ingo_Exception + * @throws Horde_Exception_NotFound + */ + public function getScript() + { + $cmdList = sprintf("echo '%s' | %s -s %s -p %s -u %s --list | grep ACTIVE", + $this->_params['password'], + $this->_params['script'], + $this->_params['hostspec'], + $this->_params['port'], + $this->_params['username'] + ); + $files = shell_exec($cmdList); + list(, $name,) = explode('"', $files, 3); + $cmdDownload = sprintf("echo '%s' | %s -s %s -p %s -u %s --download --localsieve - --remotesieve %s", + $this->_params['password'], + $this->_params['script'], + $this->_params['hostspec'], + $this->_params['port'], + $this->_params['username'], + $name + ); + $rules = shell_exec($cmdDownload); + + return array('name' => $name, 'script' => $rules); + } +} diff --git a/lib/Transport/Timsieved.php b/lib/Transport/Timsieved.php index e818681..124a672 100644 --- a/lib/Transport/Timsieved.php +++ b/lib/Transport/Timsieved.php @@ -125,7 +125,7 @@ public function setScriptActive($script) /** * Returns the content of the currently active script. * - * @return string The complete ruleset of the specified user. + * @return array Keys 'name' (string) the active script, 'script' (string) The complete ruleset of the specified user. * @throws Ingo_Exception * @throws Horde_Exception_NotFound */