Overview

Packages

  • Horde
    • Icalendar
      • UnitTests
  • Ingo
    • UnitTests
  • None

Classes

  • Horde_Core_Ui_VarRenderer_Ingo
  • Ingo
  • Ingo_Api
  • Ingo_Exception
  • Ingo_Exception_Pear
  • Ingo_LoginTasks_SystemTask_Upgrade
  • Ingo_Script
  • Ingo_Script_Imap
  • Ingo_Script_Imap_Api
  • Ingo_Script_Imap_Live
  • Ingo_Script_Maildrop
  • Ingo_Script_Maildrop_Comment
  • Ingo_Script_Maildrop_Recipe
  • Ingo_Script_Maildrop_Variable
  • Ingo_Script_Procmail
  • Ingo_Script_Procmail_Comment
  • Ingo_Script_Procmail_Recipe
  • Ingo_Script_Procmail_Variable
  • Ingo_Script_Sieve
  • Ingo_Script_Sieve_Action
  • Ingo_Script_Sieve_Action_Addflag
  • Ingo_Script_Sieve_Action_Discard
  • Ingo_Script_Sieve_Action_Fileinto
  • Ingo_Script_Sieve_Action_Flag
  • Ingo_Script_Sieve_Action_Keep
  • Ingo_Script_Sieve_Action_Notify
  • Ingo_Script_Sieve_Action_Redirect
  • Ingo_Script_Sieve_Action_Reject
  • Ingo_Script_Sieve_Action_Removeflag
  • Ingo_Script_Sieve_Action_Stop
  • Ingo_Script_Sieve_Action_Vacation
  • Ingo_Script_Sieve_Comment
  • Ingo_Script_Sieve_Else
  • Ingo_Script_Sieve_Elsif
  • Ingo_Script_Sieve_If
  • Ingo_Script_Sieve_Test
  • Ingo_Script_Sieve_Test_Address
  • Ingo_Script_Sieve_Test_Allof
  • Ingo_Script_Sieve_Test_Anyof
  • Ingo_Script_Sieve_Test_Body
  • Ingo_Script_Sieve_Test_Exists
  • Ingo_Script_Sieve_Test_False
  • Ingo_Script_Sieve_Test_Header
  • Ingo_Script_Sieve_Test_Not
  • Ingo_Script_Sieve_Test_Relational
  • Ingo_Script_Sieve_Test_Size
  • Ingo_Script_Sieve_Test_True
  • Ingo_Storage
  • Ingo_Storage_Blacklist
  • Ingo_Storage_Filters
  • Ingo_Storage_Filters_Sql
  • Ingo_Storage_Forward
  • Ingo_Storage_Mock
  • Ingo_Storage_Prefs
  • Ingo_Storage_Rule
  • Ingo_Storage_Spam
  • Ingo_Storage_Sql
  • Ingo_Storage_Vacation
  • Ingo_Storage_VacationTest
  • Ingo_Storage_Whitelist
  • Ingo_Test
  • Ingo_Transport
  • Ingo_Transport_Ldap
  • Ingo_Transport_Null
  • Ingo_Transport_Sivtest
  • Ingo_Transport_Timsieved
  • Ingo_Transport_Vfs
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Ingo_Transport_Timsieved implements the Sieve_Driver api to allow scripts
  4:  * to be installed and set active via a Cyrus timsieved server.
  5:  *
  6:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file LICENSE for license information (ASL).  If you
  9:  * did not receive this file, see http://www.horde.org/licenses/apache.
 10:  *
 11:  * @author  Mike Cochrane <mike@graftonhall.co.nz>
 12:  * @author  Jan Schneider <jan@horde.org>
 13:  * @package Ingo
 14:  */
 15: class Ingo_Transport_Timsieved extends Ingo_Transport
 16: {
 17:     /**
 18:      * The Net_Sieve object.
 19:      *
 20:      * @var Net_Sieve
 21:      */
 22:     protected $_sieve;
 23: 
 24:     /**
 25:      * Constructor.
 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:      * Connects to the sieve server.
 46:      *
 47:      * @throws Ingo_Exception
 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:         /* BC for older Net_Sieve versions that don't allow specify the debug
 78:          * handler in the constructor. */
 79:         if (!empty($this->_params['debug'])) {
 80:             Ingo_Exception_Pear::catchError($this->_sieve->setDebug(true, array($this, 'debug')));
 81:         }
 82:     }
 83: 
 84:     /**
 85:      * Routes the Sieve protocol log to the Horde log.
 86:      *
 87:      * @param Net_Sieve $sieve  A Net_Sieve object.
 88:      * @param string $message   The tracked Sieve communication.
 89:      */
 90:     public function debug($sieve, $message)
 91:     {
 92:         Horde::logMessage($message, 'DEBUG');
 93:     }
 94: 
 95:     /**
 96:      * Sets a script running on the backend.
 97:      *
 98:      * @param string $script     The filter script.
 99:      * @param array $additional  Any additional scripts that need to uploaded.
100:      *
101:      * @throws Ingo_Exception
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:      * Uploads additional scripts.
120:      *
121:      * This doesn't make much sense in Sieve though, because only one script
122:      * can be active at any time.
123:      *
124:      * @param array $additional  Any additional scripts that need to uploaded.
125:      *
126:      * @throws Ingo_Exception
127:      */
128:     protected function _uploadAdditional($additional = array())
129:     {
130:         /* Delete first. */
131:         foreach ($additional as $scriptname => $script) {
132:             if (!strlen($script)) {
133:                 Ingo_Exception_Pear::catchError($this->_sieve->removeScript($scriptname));
134:             }
135:         }
136: 
137:         /* Now upload. */
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:      * Returns the content of the currently active script.
148:      *
149:      * @return string  The complete ruleset of the specified user.
150:      * @throws Ingo_Exception
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: 
API documentation generated by ApiGen