Skip to content

Commit

Permalink
Merge pull request #2 from ralflang/feature_transport_sieveconnect
Browse files Browse the repository at this point in the history
Feature transport sieveconnect
  • Loading branch information
ralflang authored Mar 28, 2024
2 parents 08269f5 + 417e28a commit 2d38aac
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 1 deletion.
115 changes: 115 additions & 0 deletions lib/Transport/Sieveconnect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/**
* Copyright 2017-2018 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @author Ralf Lang <[email protected]>
* @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 <[email protected]>
* @author Jan Schneider <[email protected]>
* @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);
}
}
2 changes: 1 addition & 1 deletion lib/Transport/Timsieved.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 2d38aac

Please sign in to comment.