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_Sivtest implements the Sieve_Driver api to allow scripts to
  4:  * be installed and set active via the Cyrus sivtest command line utility.
  5:  *
  6:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  7:  * Copyright 2004-2007 Liam Hoekenga <liamr@umich.edu>
  8:  *
  9:  * See the enclosed file LICENSE for license information (ASL).  If you
 10:  * did not receive this file, see http://www.horde.org/licenses/apache.
 11:  *
 12:  * @author  Mike Cochrane <mike@graftonhall.co.nz>
 13:  * @author  Jan Schneider <jan@horde.org>
 14:  * @author  Liam Hoekenga <liamr@umich.edu>
 15:  * @package Ingo
 16:  */
 17: class Ingo_Transport_Sivtest extends Ingo_Transport_Timsieved
 18: {
 19:     /**
 20:      * Constructor.
 21:      */
 22:     public function __construct($params = array())
 23:     {
 24:         $default_params = array(
 25:             'hostspec'   => 'localhost',
 26:             'logintype'  => '',
 27:             'port'       => 4190,
 28:             'scriptname' => 'ingo',
 29:             'admin'      => '',
 30:             'usetls'     => true,
 31:             'command'    => '',
 32:             'socket'     => '',
 33:         );
 34: 
 35:         parent::__construct(array_merge($default_params, $params));
 36: 
 37:         $this->_support_shares = false;
 38:     }
 39: 
 40:     /**
 41:      * Connect to the sieve server.
 42:      *
 43:      * @throws Ingo_Exception;
 44:      */
 45:     protected function _connect()
 46:     {
 47:         if (!empty($this->_sieve)) {
 48:             return;
 49:         }
 50: 
 51:         $this->sivtestSocket(
 52:             $this->_params['username'],
 53:             $this->_params['password'],
 54:             $this->_params['hostspec']);
 55: 
 56:         $this->_sieve = new Net_Sieve(
 57:             $this->_params['username'],
 58:             $this->_params['password'],
 59:             'unix://' . $this->_params['socket'],
 60:             0,
 61:             null,
 62:             null,
 63:             false,
 64:             true,
 65:             $this->_params['usetls']);
 66: 
 67:         $res = $this->_sieve->getError();
 68:         if ($res instanceof PEAR_Error) {
 69:             unset($this->_sieve);
 70:             throw new Ingo_Exception($res);
 71:         }
 72:     }
 73: 
 74:     /**
 75:      * Used to figure out which Sieve server the script will be run
 76:      * on, and then open a GSSAPI authenticated socket to said server.
 77:      *
 78:      * @param string $username  The username.
 79:      * @param string $password  The password.
 80:      * @param string $hostspec  The hostspec.
 81:      *
 82:      * @return TODO
 83:      * @throws Ingo_Exception
 84:      */
 85:     public function sivtestSocket($username, $password, $hostspec)
 86:     {
 87:         $command = '';
 88:         $error_return = '';
 89: 
 90:         if (strtolower($this->_params['logintype']) == 'gssapi' &&
 91:             isset($_SERVER['KRB5CCNAME'])) {
 92:             $command .= 'KRB5CCNAME=' . $_SERVER['KRB5CCNAME'];
 93:         }
 94: 
 95:         $domain_socket = 'unix://' . $this->_params['socket'];
 96: 
 97:         $command .= ' ' . $this->_params['command']
 98:             . ' -m ' . $this->_params['logintype']
 99:             . ' -u ' . $username
100:             . ' -a ' . $username
101:             . ' -w ' . $password
102:             . ' -p ' . $this->_params['port']
103:             . ' -X ' . $this->_params['socket']
104:             . ' ' . $hostspec;
105: 
106:         $conn_attempts = 0;
107:         while ($conn_attempts++ < 4) {
108:             $attempts = 0;
109:             if (!file_exists($this->_params['socket'])) {
110:                 exec($command . ' > /dev/null 2>&1');
111:                 sleep(1);
112:                 while (!file_exists($this->_params['socket'])) {
113:                     usleep(200000);
114:                     if ($attempts++ > 5) {
115:                         $error_return = ': No socket after 10 seconds of trying!';
116:                         continue 2;
117:                     }
118:                 }
119:             }
120:             $socket = new Net_Socket();
121:             $error = $socket->connect($domain_socket, 0, true, 30);
122:             if (!($error instanceof PEAR_Error)) {
123:                 break;
124:             }
125: 
126:             // We failed, break this connection.
127:             unlink($this->_params['socket']);
128:         }
129: 
130:         if (!empty($error_return)) {
131:             throw new Ingo_Exception($error_return);
132:         }
133: 
134:         $status = $socket->getStatus();
135:         if ($status instanceof PEAR_Error || $status['eof']) {
136:             throw new Ingo_Exception(_("Failed to write to socket: (connection lost!)"));
137:         }
138: 
139:         $error = $socket->writeLine("CAPABILITY");
140:         if ($error instanceof PEAR_Error) {
141:             throw new Ingo_Exception(_("Failed to write to socket: " . $error->getMessage()));
142:         }
143: 
144:         $result = $socket->readLine();
145:         if ($result instanceof PEAR_Error) {
146:             throw new Ingo_Exception(_("Failed to read from socket: " . $error->getMessage()));
147:         }
148: 
149:         if (preg_match('|^bye \(referral "(sieve://)?([^"]+)|i',
150:                        $result, $matches)) {
151:             $socket->disconnect();
152: 
153:             $this->sivtestSocket($username, $password, $matches[2]);
154:         } else {
155:             $socket->disconnect();
156:             exec($command . ' > /dev/null 2>&1');
157:             sleep(1);
158:         }
159:     }
160: 
161: }
162: 
API documentation generated by ApiGen