1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Ingo_Transport_Timsieved extends Ingo_Transport
16: {
17: 18: 19: 20: 21:
22: protected $_sieve;
23:
24: 25: 26:
27: public function __construct($params = array())
28: {
29: $this->_support_shares = true;
30:
31: $default_params = array(
32: 'hostspec' => 'localhost',
33: 'logintype' => 'PLAIN',
34: 'port' => 4190,
35: 'scriptname' => 'ingo',
36: 'admin' => '',
37: 'usetls' => true,
38: 'debug' => false
39: );
40:
41: parent::__construct(array_merge($default_params, $params));
42: }
43:
44: 45: 46: 47: 48:
49: protected function _connect()
50: {
51: if (!empty($this->_sieve)) {
52: return;
53: }
54:
55: $auth = empty($this->_params['admin'])
56: ? $this->_params['username']
57: : $this->_params['admin'];
58:
59: $this->_sieve = new Net_Sieve($auth,
60: $this->_params['password'],
61: $this->_params['hostspec'],
62: $this->_params['port'],
63: $this->_params['logintype'],
64: Ingo::getUser(false),
65: $this->_params['debug'],
66: false,
67: $this->_params['usetls'],
68: null,
69: array($this, 'debug'));
70:
71: $res = $this->_sieve->getError();
72: if ($res instanceof PEAR_Error) {
73: unset($this->_sieve);
74: throw new Ingo_Exception($res);
75: }
76:
77: 78:
79: if (!empty($this->_params['debug'])) {
80: Ingo_Exception_Pear::catchError($this->_sieve->setDebug(true, array($this, 'debug')));
81: }
82: }
83:
84: 85: 86: 87: 88: 89:
90: public function debug($sieve, $message)
91: {
92: Horde::logMessage($message, 'DEBUG');
93: }
94:
95: 96: 97: 98: 99: 100: 101: 102:
103: public function setScriptActive($script, $additional = array())
104: {
105: $this->_connect();
106:
107: if (!strlen($script)) {
108: Ingo_Exception_Pear::catchError($this->_sieve->setActive(''));
109: $this->_uploadAdditional($additional);
110: return;
111: }
112:
113: Ingo_Exception_Pear::catchError($this->_sieve->haveSpace($this->_params['scriptname'], strlen($script)));
114: Ingo_Exception_Pear::catchError($this->_sieve->installScript($this->_params['scriptname'], $script, true));
115: $this->_uploadAdditional($additional);
116: }
117:
118: 119: 120: 121: 122: 123: 124: 125: 126: 127:
128: protected function _uploadAdditional($additional = array())
129: {
130:
131: foreach ($additional as $scriptname => $script) {
132: if (!strlen($script)) {
133: Ingo_Exception_Pear::catchError($this->_sieve->removeScript($scriptname));
134: }
135: }
136:
137:
138: foreach ($additional as $scriptname => $script) {
139: if (strlen($script)) {
140: Ingo_Exception_Pear::catchError($this->_sieve->haveSpace($scriptname, strlen($script)));
141: Ingo_Exception_Pear::catchError($this->_sieve->installScript($scriptname, $script));
142: }
143: }
144: }
145:
146: 147: 148: 149: 150: 151:
152: public function getScript()
153: {
154: $this->_connect();
155: $active = Ingo_Exception_Pear::catchError($this->_sieve->getActive());
156:
157: return empty($active)
158: ? ''
159: : Ingo_Exception_Pear::catchError($this->_sieve->getScript($active));
160: }
161: }
162: