annotate vendor/pear/net_sieve/Sieve.php @ 0:1e000243b222

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:50:29 -0500
parents
children 05c4c32948af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 <?php
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3 * This file contains the Net_Sieve class.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 * PHP version 5
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 * +-----------------------------------------------------------------------+
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 * | All rights reserved. |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 * | |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 * | Redistribution and use in source and binary forms, with or without |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 * | modification, are permitted provided that the following conditions |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 * | are met: |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 * | |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 * | o Redistributions of source code must retain the above copyright |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 * | notice, this list of conditions and the following disclaimer. |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 * | o Redistributions in binary form must reproduce the above copyright |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
17 * | notice, this list of conditions and the following disclaimer in the |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 * | documentation and/or other materials provided with the distribution.|
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19 * | |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20 * | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21 * | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
22 * | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23 * | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24 * | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 * | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 * | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27 * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30 * | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 * +-----------------------------------------------------------------------+
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 * @category Networking
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 * @package Net_Sieve
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35 * @author Richard Heyes <richard@phpguru.org>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36 * @author Damian Fernandez Sosa <damlists@cnba.uba.ar>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37 * @author Anish Mistry <amistry@am-productions.biz>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38 * @author Jan Schneider <jan@horde.org>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 * @copyright 2002-2003 Richard Heyes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40 * @copyright 2006-2008 Anish Mistry
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 * @link http://pear.php.net/package/Net_Sieve
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 require_once 'PEAR.php';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 require_once 'Net/Socket.php';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 * TODO
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51 * o supportsAuthMech()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 * Disconnected state
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56 * @const NET_SIEVE_STATE_DISCONNECTED
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58 define('NET_SIEVE_STATE_DISCONNECTED', 1, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
60 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61 * Authorisation state
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 * @const NET_SIEVE_STATE_AUTHORISATION
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64 define('NET_SIEVE_STATE_AUTHORISATION', 2, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67 * Transaction state
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68 * @const NET_SIEVE_STATE_TRANSACTION
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 define('NET_SIEVE_STATE_TRANSACTION', 3, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 * A class for talking to the timsieved server which comes with Cyrus IMAP.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
76 * @category Networking
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77 * @package Net_Sieve
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78 * @author Richard Heyes <richard@phpguru.org>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79 * @author Damian Fernandez Sosa <damlists@cnba.uba.ar>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80 * @author Anish Mistry <amistry@am-productions.biz>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81 * @author Jan Schneider <jan@horde.org>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 * @copyright 2002-2003 Richard Heyes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 * @copyright 2006-2008 Anish Mistry
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84 * @license http://www.opensource.org/licenses/bsd-license.php BSD
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85 * @version Release: @package_version@
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86 * @link http://pear.php.net/package/Net_Sieve
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87 * @link http://tools.ietf.org/html/rfc5228 RFC 5228 (Sieve: An Email
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
88 * Filtering Language)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 * @link http://tools.ietf.org/html/rfc5804 RFC 5804 A Protocol for
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 * Remotely Managing Sieve Scripts
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92 class Net_Sieve
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
94 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95 * The authentication methods this class supports.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97 * Can be overwritten if having problems with certain methods.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 * @var array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101 var $supportedAuthMethods = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102 'DIGEST-MD5',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103 'CRAM-MD5',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104 'EXTERNAL',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105 'PLAIN' ,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106 'LOGIN'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110 * SASL authentication methods that require Auth_SASL.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 * @var array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 var $supportedSASLAuthMethods = array('DIGEST-MD5', 'CRAM-MD5');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
117 * The socket handle.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119 * @var resource
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 var $_sock;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 * Parameters and connection information.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126 * @var array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
128 var $_data;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131 * Current state of the connection.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133 * One of the NET_SIEVE_STATE_* constants.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135 * @var integer
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137 var $_state;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140 * PEAR object to avoid strict warnings.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
141 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
142 * @var PEAR_Error
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144 var $_pear;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147 * Constructor error.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 * @var PEAR_Error
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151 var $_error;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 * Whether to enable debugging.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 * @var boolean
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158 var $_debug = false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161 * Debug output handler.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163 * This has to be a valid callback.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165 * @var string|array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167 var $_debug_handler = null;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 * Whether to pick up an already established connection.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 * @var boolean
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174 var $_bypassAuth = false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177 * Whether to use TLS if available.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179 * @var boolean
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181 var $_useTLS = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184 * Additional options for stream_context_create().
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 * @var array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 var $_options = null;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191 * Maximum number of referral loops
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 * @var array
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195 var $_maxReferralCount = 15;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198 * Constructor.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200 * Sets up the object, connects to the server and logs in. Stores any
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201 * generated error in $this->_error, which can be retrieved using the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202 * getError() method.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204 * @param string $user Login username.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205 * @param string $pass Login password.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206 * @param string $host Hostname of server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207 * @param string $port Port of server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208 * @param string $logintype Type of login to perform (see
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209 * $supportedAuthMethods).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 * @param string $euser Effective user. If authenticating as an
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211 * administrator, login as this user.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212 * @param boolean $debug Whether to enable debugging (@see setDebug()).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213 * @param string $bypassAuth Skip the authentication phase. Useful if the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214 * socket is already open.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
215 * @param boolean $useTLS Use TLS if available.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
216 * @param array $options Additional options for
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
217 * stream_context_create().
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
218 * @param mixed $handler A callback handler for the debug output.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
219 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
220 function __construct($user = null, $pass = null, $host = 'localhost',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
221 $port = 2000, $logintype = '', $euser = '',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
222 $debug = false, $bypassAuth = false, $useTLS = true,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
223 $options = null, $handler = null
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
224 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
225 $this->_pear = new PEAR();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 $this->_state = NET_SIEVE_STATE_DISCONNECTED;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227 $this->_data['user'] = $user;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
228 $this->_data['pass'] = $pass;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
229 $this->_data['host'] = $host;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
230 $this->_data['port'] = $port;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
231 $this->_data['logintype'] = $logintype;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
232 $this->_data['euser'] = $euser;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
233 $this->_sock = new Net_Socket();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
234 $this->_bypassAuth = $bypassAuth;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
235 $this->_useTLS = $useTLS;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
236 $this->_options = (array) $options;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
237 $this->setDebug($debug, $handler);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239 /* Try to include the Auth_SASL package. If the package is not
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240 * available, we disable the authentication methods that depend upon
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241 * it. */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242 if ((@include_once 'Auth/SASL.php') === false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243 $this->_debug('Auth_SASL not present');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244 $this->supportedAuthMethods = array_diff(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 $this->supportedAuthMethods,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
246 $this->supportedSASLAuthMethods
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
247 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
249
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
250 if (strlen($user) && strlen($pass)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251 $this->_error = $this->_handleConnectAndLogin();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256 * Returns any error that may have been generated in the constructor.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258 * @return boolean|PEAR_Error False if no error, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
259 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
260 function getError()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
262 return is_a($this->_error, 'PEAR_Error') ? $this->_error : false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
263 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
264
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266 * Sets the debug state and handler function.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268 * @param boolean $debug Whether to enable debugging.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
269 * @param string $handler A custom debug handler. Must be a valid callback.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
270 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
271 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
272 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273 function setDebug($debug = true, $handler = null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275 $this->_debug = $debug;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276 $this->_debug_handler = $handler;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280 * Connects to the server and logs in.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 * @return boolean True on success, PEAR_Error on failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284 function _handleConnectAndLogin()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
285 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
286 $res = $this->connect($this->_data['host'], $this->_data['port'], $this->_options, $this->_useTLS);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
289 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
290 if ($this->_bypassAuth === false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291 $res = $this->login($this->_data['user'], $this->_data['pass'], $this->_data['logintype'], $this->_data['euser'], $this->_bypassAuth);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
293 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
294 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
295 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
296 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
297 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
298
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
299 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
300 * Handles connecting to the server and checks the response validity.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
301 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
302 * @param string $host Hostname of server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
303 * @param string $port Port of server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
304 * @param array $options List of options to pass to
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
305 * stream_context_create().
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
306 * @param boolean $useTLS Use TLS if available.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
307 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
308 * @return boolean True on success, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
309 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
310 function connect($host, $port, $options = null, $useTLS = true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
311 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
312 $this->_data['host'] = $host;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
313 $this->_data['port'] = $port;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
314 $this->_useTLS = $useTLS;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
315
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
316 if (is_array($options)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
317 $this->_options = array_merge($this->_options, $options);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
318 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
319
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
320 if (NET_SIEVE_STATE_DISCONNECTED != $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
321 return $this->_pear->raiseError('Not currently in DISCONNECTED state', 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
322 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
323
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
324 $res = $this->_sock->connect($host, $port, false, 5, $options);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
325 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
326 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
327 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
328
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
329 if ($this->_bypassAuth) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
330 $this->_state = NET_SIEVE_STATE_TRANSACTION;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
331 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
332 $this->_state = NET_SIEVE_STATE_AUTHORISATION;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
333 $res = $this->_doCmd();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
334 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
335 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
336 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
337 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
338
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
339 // Explicitly ask for the capabilities in case the connection is
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
340 // picked up from an existing connection.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
341 $res = $this->_cmdCapability();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
342 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
343 return $this->_pear->raiseError(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
344 'Failed to connect, server said: ' . $res->getMessage(), 2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
345 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
346 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
347
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
348 // Check if we can enable TLS via STARTTLS.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
349 if ($useTLS && !empty($this->_capability['starttls'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
350 && function_exists('stream_socket_enable_crypto')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
351 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
352 $res = $this->_startTLS();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
353 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
354 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
355 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
356 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
357
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
358 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
359 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
360
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
361 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
362 * Disconnect from the Sieve server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
363 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
364 * @param boolean $sendLogoutCMD Whether to send LOGOUT command before
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
365 * disconnecting.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
366 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
367 * @return boolean True on success, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
368 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
369 function disconnect($sendLogoutCMD = true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
370 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
371 return $this->_cmdLogout($sendLogoutCMD);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
372 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
373
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
374 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
375 * Logs into server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
376 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
377 * @param string $user Login username.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
378 * @param string $pass Login password.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
379 * @param string $logintype Type of login method to use.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
380 * @param string $euser Effective UID (perform on behalf of $euser).
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
381 * @param boolean $bypassAuth Do not perform authentication.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
382 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
383 * @return boolean True on success, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
384 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
385 function login($user, $pass, $logintype = null, $euser = '', $bypassAuth = false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
386 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
387 $this->_data['user'] = $user;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
388 $this->_data['pass'] = $pass;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
389 $this->_data['logintype'] = $logintype;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
390 $this->_data['euser'] = $euser;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
391 $this->_bypassAuth = $bypassAuth;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
392
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
393 if (NET_SIEVE_STATE_AUTHORISATION != $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
394 return $this->_pear->raiseError('Not currently in AUTHORISATION state', 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
395 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
396
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
397 if (!$bypassAuth ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
398 $res = $this->_cmdAuthenticate($user, $pass, $logintype, $euser);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
399 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
400 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
401 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
402 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
403 $this->_state = NET_SIEVE_STATE_TRANSACTION;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
404
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
405 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
406 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
407
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
408 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
409 * Returns an indexed array of scripts currently on the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
410 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
411 * @return array Indexed array of scriptnames.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
412 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
413 function listScripts()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
414 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
415 if (is_array($scripts = $this->_cmdListScripts())) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
416 return $scripts[0];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
417 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
418 return $scripts;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
419 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
420 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
421
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
422 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
423 * Returns the active script.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
424 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
425 * @return string The active scriptname.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
426 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
427 function getActive()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
428 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
429 if (is_array($scripts = $this->_cmdListScripts())) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
430 return $scripts[1];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
431 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
432 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
433
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
434 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
435 * Sets the active script.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
436 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
437 * @param string $scriptname The name of the script to be set as active.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
438 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
439 * @return boolean True on success, PEAR_Error on failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
440 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
441 function setActive($scriptname)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
442 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
443 return $this->_cmdSetActive($scriptname);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
444 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
445
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
446 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
447 * Retrieves a script.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
448 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
449 * @param string $scriptname The name of the script to be retrieved.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
450 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
451 * @return string The script on success, PEAR_Error on failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
452 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
453 function getScript($scriptname)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
454 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
455 return $this->_cmdGetScript($scriptname);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
456 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
457
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
458 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
459 * Adds a script to the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
460 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
461 * @param string $scriptname Name of the script.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
462 * @param string $script The script content.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
463 * @param boolean $makeactive Whether to make this the active script.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
464 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
465 * @return boolean True on success, PEAR_Error on failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
466 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
467 function installScript($scriptname, $script, $makeactive = false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
468 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
469 $res = $this->_cmdPutScript($scriptname, $script);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
470 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
471 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
472 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
473 if ($makeactive) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
474 return $this->_cmdSetActive($scriptname);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
475 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
476 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
477 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
478
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
479 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
480 * Removes a script from the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
481 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
482 * @param string $scriptname Name of the script.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
483 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
484 * @return boolean True on success, PEAR_Error on failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
485 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
486 function removeScript($scriptname)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
487 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
488 return $this->_cmdDeleteScript($scriptname);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
489 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
490
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
491 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
492 * Checks if the server has space to store the script by the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
493 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
494 * @param string $scriptname The name of the script to mark as active.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
495 * @param integer $size The size of the script.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
496 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
497 * @return boolean|PEAR_Error True if there is space, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
498 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
499 * @todo Rename to hasSpace()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
500 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
501 function haveSpace($scriptname, $size)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
502 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
503 if (NET_SIEVE_STATE_TRANSACTION != $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
504 return $this->_pear->raiseError('Not currently in TRANSACTION state', 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
505 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
506
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
507 $res = $this->_doCmd(sprintf('HAVESPACE %s %d', $this->_escape($scriptname), $size));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
508 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
509 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
510 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
511 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
512 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
513
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
514 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
515 * Returns the list of extensions the server supports.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
516 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
517 * @return array List of extensions or PEAR_Error on failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
518 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
519 function getExtensions()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
520 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
521 if (NET_SIEVE_STATE_DISCONNECTED == $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
522 return $this->_pear->raiseError('Not currently connected', 7);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
523 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
524 return $this->_capability['extensions'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
525 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
526
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
527 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
528 * Returns whether the server supports an extension.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
529 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
530 * @param string $extension The extension to check.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
531 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
532 * @return boolean Whether the extension is supported or PEAR_Error on
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
533 * failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
534 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
535 function hasExtension($extension)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
536 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
537 if (NET_SIEVE_STATE_DISCONNECTED == $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
538 return $this->_pear->raiseError('Not currently connected', 7);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
539 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
540
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
541 $extension = trim($this->_toUpper($extension));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
542 if (is_array($this->_capability['extensions'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
543 foreach ($this->_capability['extensions'] as $ext) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
544 if ($ext == $extension) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
545 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
546 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
547 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
548 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
549
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
550 return false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
551 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
552
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
553 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
554 * Returns the list of authentication methods the server supports.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
555 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
556 * @return array List of authentication methods or PEAR_Error on failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
557 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
558 function getAuthMechs()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
559 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
560 if (NET_SIEVE_STATE_DISCONNECTED == $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
561 return $this->_pear->raiseError('Not currently connected', 7);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
562 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
563 return $this->_capability['sasl'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
564 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
565
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
566 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
567 * Returns whether the server supports an authentication method.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
568 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
569 * @param string $method The method to check.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
570 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
571 * @return boolean Whether the method is supported or PEAR_Error on
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
572 * failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
573 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
574 function hasAuthMech($method)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
575 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
576 if (NET_SIEVE_STATE_DISCONNECTED == $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
577 return $this->_pear->raiseError('Not currently connected', 7);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
578 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
579
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
580 $method = trim($this->_toUpper($method));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
581 if (is_array($this->_capability['sasl'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
582 foreach ($this->_capability['sasl'] as $sasl) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
583 if ($sasl == $method) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
584 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
585 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
586 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
587 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
588
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
589 return false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
590 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
591
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
592 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
593 * Handles the authentication using any known method.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
594 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
595 * @param string $uid The userid to authenticate as.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
596 * @param string $pwd The password to authenticate with.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
597 * @param string $userMethod The method to use. If empty, the class chooses
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
598 * the best (strongest) available method.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
599 * @param string $euser The effective uid to authenticate as.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
600 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
601 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
602 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
603 function _cmdAuthenticate($uid, $pwd, $userMethod = null, $euser = '')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
604 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
605 $method = $this->_getBestAuthMethod($userMethod);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
606 if (is_a($method, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
607 return $method;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
608 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
609 switch ($method) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
610 case 'DIGEST-MD5':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
611 return $this->_authDigestMD5($uid, $pwd, $euser);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
612 case 'CRAM-MD5':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
613 $result = $this->_authCRAMMD5($uid, $pwd, $euser);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
614 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
615 case 'LOGIN':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
616 $result = $this->_authLOGIN($uid, $pwd, $euser);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
617 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
618 case 'PLAIN':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
619 $result = $this->_authPLAIN($uid, $pwd, $euser);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
620 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
621 case 'EXTERNAL':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
622 $result = $this->_authEXTERNAL($uid, $pwd, $euser);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
623 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
624 default :
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
625 $result = $this->_pear->raiseError(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
626 $method . ' is not a supported authentication method'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
627 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
628 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
629 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
630
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
631 $res = $this->_doCmd();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
632 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
633 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
634 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
635
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
636 // Query the server capabilities again now that we are authenticated.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
637 if ($this->_pear->isError($res = $this->_cmdCapability())) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
638 return $this->_pear->raiseError(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
639 'Failed to connect, server said: ' . $res->getMessage(), 2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
640 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
641 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
642
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
643 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
644 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
645
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
646 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
647 * Authenticates the user using the PLAIN method.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
648 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
649 * @param string $user The userid to authenticate as.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
650 * @param string $pass The password to authenticate with.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
651 * @param string $euser The effective uid to authenticate as.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
652 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
653 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
654 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
655 function _authPLAIN($user, $pass, $euser)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
656 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
657 return $this->_sendCmd(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
658 sprintf(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
659 'AUTHENTICATE "PLAIN" "%s"',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
660 base64_encode($euser . chr(0) . $user . chr(0) . $pass)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
661 )
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
662 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
663 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
664
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
665 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
666 * Authenticates the user using the LOGIN method.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
667 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
668 * @param string $user The userid to authenticate as.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
669 * @param string $pass The password to authenticate with.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
670 * @param string $euser The effective uid to authenticate as. Not used.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
671 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
672 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
673 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
674 function _authLOGIN($user, $pass, $euser)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
675 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
676 $result = $this->_sendCmd('AUTHENTICATE "LOGIN"');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
677 if (is_a($result, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
678 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
679 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
680 $result = $this->_doCmd('"' . base64_encode($user) . '"', true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
681 if (is_a($result, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
682 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
683 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
684 return $this->_doCmd('"' . base64_encode($pass) . '"', true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
685 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
686
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
687 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
688 * Authenticates the user using the CRAM-MD5 method.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
689 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
690 * @param string $user The userid to authenticate as.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
691 * @param string $pass The password to authenticate with.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
692 * @param string $euser The effective uid to authenticate as. Not used.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
693 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
694 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
695 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
696 function _authCRAMMD5($user, $pass, $euser)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
697 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
698 $challenge = $this->_doCmd('AUTHENTICATE "CRAM-MD5"', true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
699 if (is_a($challenge, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
700 return $challenge;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
701 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
702
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
703 $auth_sasl = new Auth_SASL;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
704 $cram = $auth_sasl->factory('crammd5');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
705 $challenge = base64_decode(trim($challenge));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
706 $response = $cram->getResponse($user, $pass, $challenge);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
707
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
708 if (is_a($response, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
709 return $response;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
710 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
711
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
712 return $this->_sendStringResponse(base64_encode($response));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
713 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
714
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
715 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
716 * Authenticates the user using the DIGEST-MD5 method.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
717 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
718 * @param string $user The userid to authenticate as.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
719 * @param string $pass The password to authenticate with.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
720 * @param string $euser The effective uid to authenticate as.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
721 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
722 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
723 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
724 function _authDigestMD5($user, $pass, $euser)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
725 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
726 $challenge = $this->_doCmd('AUTHENTICATE "DIGEST-MD5"', true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
727 if (is_a($challenge, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
728 return $challenge;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
729 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
730
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
731 $auth_sasl = new Auth_SASL;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
732 $digest = $auth_sasl->factory('digestmd5');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
733 $challenge = base64_decode(trim($challenge));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
734
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
735 // @todo Really 'localhost'?
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
736 $response = $digest->getResponse($user, $pass, $challenge, 'localhost', 'sieve', $euser);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
737 if (is_a($response, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
738 return $response;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
739 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
740
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
741 $result = $this->_sendStringResponse(base64_encode($response));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
742 if (is_a($result, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
743 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
744 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
745 $result = $this->_doCmd('', true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
746 if (is_a($result, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
747 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
748 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
749 if ($this->_toUpper(substr($result, 0, 2)) == 'OK') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
750 return;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
751 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
752
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
753 /* We don't use the protocol's third step because SIEVE doesn't allow
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
754 * subsequent authentication, so we just silently ignore it. */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
755 $result = $this->_sendStringResponse('');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
756 if (is_a($result, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
757 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
758 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
759
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
760 return $this->_doCmd();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
761 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
762
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
763 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
764 * Authenticates the user using the EXTERNAL method.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
765 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
766 * @param string $user The userid to authenticate as.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
767 * @param string $pass The password to authenticate with.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
768 * @param string $euser The effective uid to authenticate as.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
769 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
770 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
771 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
772 * @since 1.1.7
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
773 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
774 function _authEXTERNAL($user, $pass, $euser)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
775 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
776 $cmd = sprintf(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
777 'AUTHENTICATE "EXTERNAL" "%s"',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
778 base64_encode(strlen($euser) ? $euser : $user)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
779 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
780 return $this->_sendCmd($cmd);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
781 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
782
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
783 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
784 * Removes a script from the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
785 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
786 * @param string $scriptname Name of the script to delete.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
787 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
788 * @return boolean True on success, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
789 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
790 function _cmdDeleteScript($scriptname)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
791 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
792 if (NET_SIEVE_STATE_TRANSACTION != $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
793 return $this->_pear->raiseError('Not currently in AUTHORISATION state', 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
794 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
795
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
796 $res = $this->_doCmd(sprintf('DELETESCRIPT %s', $this->_escape($scriptname)));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
797 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
798 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
799 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
800 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
801 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
802
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
803 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
804 * Retrieves the contents of the named script.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
805 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
806 * @param string $scriptname Name of the script to retrieve.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
807 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
808 * @return string The script if successful, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
809 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
810 function _cmdGetScript($scriptname)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
811 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
812 if (NET_SIEVE_STATE_TRANSACTION != $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
813 return $this->_pear->raiseError('Not currently in AUTHORISATION state', 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
814 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
815
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
816 $res = $this->_doCmd(sprintf('GETSCRIPT %s', $this->_escape($scriptname)));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
817 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
818 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
819 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
820
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
821 return preg_replace('/^{[0-9]+}\r\n/', '', $res);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
822 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
823
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
824 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
825 * Sets the active script, i.e. the one that gets run on new mail by the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
826 * server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
827 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
828 * @param string $scriptname The name of the script to mark as active.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
829 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
830 * @return boolean True on success, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
831 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
832 function _cmdSetActive($scriptname)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
833 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
834 if (NET_SIEVE_STATE_TRANSACTION != $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
835 return $this->_pear->raiseError('Not currently in AUTHORISATION state', 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
836 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
837
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
838 $res = $this->_doCmd(sprintf('SETACTIVE %s', $this->_escape($scriptname)));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
839 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
840 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
841 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
842
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
843 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
844 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
845
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
846 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
847 * Returns the list of scripts on the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
848 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
849 * @return array An array with the list of scripts in the first element
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
850 * and the active script in the second element on success,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
851 * PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
852 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
853 function _cmdListScripts()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
854 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
855 if (NET_SIEVE_STATE_TRANSACTION != $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
856 return $this->_pear->raiseError('Not currently in AUTHORISATION state', 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
857 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
858
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
859 $res = $this->_doCmd('LISTSCRIPTS');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
860 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
861 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
862 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
863
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
864 $scripts = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
865 $activescript = null;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
866 $res = explode("\r\n", $res);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
867 foreach ($res as $value) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
868 if (preg_match('/^"(.*)"( ACTIVE)?$/i', $value, $matches)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
869 $script_name = stripslashes($matches[1]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
870 $scripts[] = $script_name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
871 if (!empty($matches[2])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
872 $activescript = $script_name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
873 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
874 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
875 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
876
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
877 return array($scripts, $activescript);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
878 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
879
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
880 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
881 * Adds a script to the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
882 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
883 * @param string $scriptname Name of the new script.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
884 * @param string $scriptdata The new script.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
885 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
886 * @return boolean True on success, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
887 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
888 function _cmdPutScript($scriptname, $scriptdata)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
889 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
890 if (NET_SIEVE_STATE_TRANSACTION != $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
891 return $this->_pear->raiseError('Not currently in AUTHORISATION state', 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
892 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
893
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
894 $stringLength = $this->_getLineLength($scriptdata);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
895 $command = sprintf(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
896 "PUTSCRIPT %s {%d+}\r\n%s",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
897 $this->_escape($scriptname),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
898 $stringLength,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
899 $scriptdata
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
900 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
901
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
902 $res = $this->_doCmd($command);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
903 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
904 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
905 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
906
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
907 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
908 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
909
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
910 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
911 * Logs out of the server and terminates the connection.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
912 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
913 * @param boolean $sendLogoutCMD Whether to send LOGOUT command before
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
914 * disconnecting.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
915 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
916 * @return boolean True on success, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
917 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
918 function _cmdLogout($sendLogoutCMD = true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
919 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
920 if (NET_SIEVE_STATE_DISCONNECTED == $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
921 return $this->_pear->raiseError('Not currently connected', 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
922 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
923
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
924 if ($sendLogoutCMD) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
925 $res = $this->_doCmd('LOGOUT');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
926 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
927 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
928 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
929 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
930
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
931 $this->_sock->disconnect();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
932 $this->_state = NET_SIEVE_STATE_DISCONNECTED;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
933
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
934 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
935 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
936
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
937 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
938 * Sends the CAPABILITY command
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
939 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
940 * @return boolean True on success, PEAR_Error otherwise.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
941 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
942 function _cmdCapability()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
943 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
944 if (NET_SIEVE_STATE_DISCONNECTED == $this->_state) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
945 return $this->_pear->raiseError('Not currently connected', 1);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
946 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
947 $res = $this->_doCmd('CAPABILITY');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
948 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
949 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
950 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
951 $this->_parseCapability($res);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
952 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
953 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
954
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
955 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
956 * Parses the response from the CAPABILITY command and stores the result
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
957 * in $_capability.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
958 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
959 * @param string $data The response from the capability command.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
960 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
961 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
962 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
963 function _parseCapability($data)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
964 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
965 // Clear the cached capabilities.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
966 $this->_capability = array('sasl' => array(),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
967 'extensions' => array());
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
968
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
969 $data = preg_split('/\r?\n/', $this->_toUpper($data), -1, PREG_SPLIT_NO_EMPTY);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
970
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
971 for ($i = 0; $i < count($data); $i++) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
972 if (!preg_match('/^"([A-Z]+)"( "(.*)")?$/', $data[$i], $matches)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
973 continue;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
974 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
975 switch ($matches[1]) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
976 case 'IMPLEMENTATION':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
977 $this->_capability['implementation'] = $matches[3];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
978 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
979
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
980 case 'SASL':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
981 $this->_capability['sasl'] = preg_split('/\s+/', $matches[3]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
982 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
983
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
984 case 'SIEVE':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
985 $this->_capability['extensions'] = preg_split('/\s+/', $matches[3]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
986 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
987
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
988 case 'STARTTLS':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
989 $this->_capability['starttls'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
990 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
991 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
992 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
993 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
994
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
995 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
996 * Sends a command to the server
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
997 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
998 * @param string $cmd The command to send.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
999 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1000 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1001 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1002 function _sendCmd($cmd)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1003 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1004 $status = $this->_sock->getStatus();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1005 if (is_a($status, 'PEAR_Error') || $status['eof']) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1006 return $this->_pear->raiseError('Failed to write to socket: connection lost');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1007 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1008 $error = $this->_sock->write($cmd . "\r\n");
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1009 if (is_a($error, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1010 return $this->_pear->raiseError(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1011 'Failed to write to socket: ' . $error->getMessage()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1012 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1013 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1014 $this->_debug("C: $cmd");
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1015 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1016
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1017 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1018 * Sends a string response to the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1019 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1020 * @param string $str The string to send.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1021 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1022 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1023 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1024 function _sendStringResponse($str)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1025 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1026 return $this->_sendCmd('{' . $this->_getLineLength($str) . "+}\r\n" . $str);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1027 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1028
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1029 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1030 * Receives a single line from the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1031 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1032 * @return string The server response line.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1033 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1034 function _recvLn()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1035 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1036 $lastline = $this->_sock->gets(8192);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1037 if (is_a($lastline, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1038 return $this->_pear->raiseError(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1039 'Failed to read from socket: ' . $lastline->getMessage()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1040 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1041 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1042
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1043 $lastline = rtrim($lastline);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1044 $this->_debug("S: $lastline");
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1045
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1046 if ($lastline === '') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1047 return $this->_pear->raiseError('Failed to read from socket');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1048 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1049
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1050 return $lastline;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1051 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1052
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1053 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1054 * Receives a number of bytes from the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1055 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1056 * @param integer $length Number of bytes to read.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1057 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1058 * @return string The server response.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1059 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1060 function _recvBytes($length)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1061 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1062 $response = '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1063 $response_length = 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1064 while ($response_length < $length) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1065 $response .= $this->_sock->read($length - $response_length);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1066 $response_length = $this->_getLineLength($response);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1067 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1068 $this->_debug('S: ' . rtrim($response));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1069 return $response;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1070 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1071
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1072 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1073 * Send a command and retrieves a response from the server.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1074 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1075 * @param string $cmd The command to send.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1076 * @param boolean $auth Whether this is an authentication command.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1077 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1078 * @return string|PEAR_Error Reponse string if an OK response, PEAR_Error
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1079 * if a NO response.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1080 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1081 function _doCmd($cmd = '', $auth = false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1082 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1083 $referralCount = 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1084 while ($referralCount < $this->_maxReferralCount) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1085 if (strlen($cmd)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1086 $error = $this->_sendCmd($cmd);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1087 if (is_a($error, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1088 return $error;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1089 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1090 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1091
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1092 $response = '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1093 while (true) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1094 $line = $this->_recvLn();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1095 if (is_a($line, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1096 return $line;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1097 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1098
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1099 if (preg_match('/^(OK|NO)/i', $line, $tag)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1100 // Check for string literal message.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1101 if (preg_match('/{([0-9]+)}$/', $line, $matches)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1102 $line = substr($line, 0, -(strlen($matches[1]) + 2))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1103 . str_replace(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1104 "\r\n", ' ', $this->_recvBytes($matches[1] + 2)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1105 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1106 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1107
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1108 if ('OK' == $this->_toUpper($tag[1])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1109 $response .= $line;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1110 return rtrim($response);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1111 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1112
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1113 return $this->_pear->raiseError(trim($response . substr($line, 2)), 3);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1114 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1115
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1116 if (preg_match('/^BYE/i', $line)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1117 $error = $this->disconnect(false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1118 if (is_a($error, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1119 return $this->_pear->raiseError(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1120 'Cannot handle BYE, the error was: '
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1121 . $error->getMessage(),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1122 4
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1123 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1124 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1125 // Check for referral, then follow it. Otherwise, carp an
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1126 // error.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1127 if (preg_match('/^bye \(referral "(sieve:\/\/)?([^"]+)/i', $line, $matches)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1128 // Replace the old host with the referral host
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1129 // preserving any protocol prefix.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1130 $this->_data['host'] = preg_replace(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1131 '/\w+(?!(\w|\:\/\/)).*/', $matches[2],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1132 $this->_data['host']
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1133 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1134 $error = $this->_handleConnectAndLogin();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1135 if (is_a($error, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1136 return $this->_pear->raiseError(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1137 'Cannot follow referral to '
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1138 . $this->_data['host'] . ', the error was: '
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1139 . $error->getMessage(),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1140 5
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1141 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1142 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1143 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1144 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1145 return $this->_pear->raiseError(trim($response . $line), 6);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1146 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1147
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1148 if (preg_match('/^{([0-9]+)}/', $line, $matches)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1149 // Matches literal string responses.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1150 $line = $this->_recvBytes($matches[1] + 2);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1151 if (!$auth) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1152 // Receive the pending OK only if we aren't
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1153 // authenticating since string responses during
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1154 // authentication don't need an OK.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1155 $this->_recvLn();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1156 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1157 return $line;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1158 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1159
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1160 if ($auth) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1161 // String responses during authentication don't need an
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1162 // OK.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1163 $response .= $line;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1164 return rtrim($response);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1165 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1166
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1167 $response .= $line . "\r\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1168 $referralCount++;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1169 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1170 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1171
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1172 return $this->_pear->raiseError('Max referral count (' . $referralCount . ') reached. Cyrus murder loop error?', 7);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1173 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1174
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1175 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1176 * Returns the name of the best authentication method that the server
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1177 * has advertised.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1178 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1179 * @param string $userMethod Only consider this method as available.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1180 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1181 * @return string The name of the best supported authentication method or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1182 * a PEAR_Error object on failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1183 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1184 function _getBestAuthMethod($userMethod = null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1185 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1186 if (!isset($this->_capability['sasl'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1187 return $this->_pear->raiseError('This server doesn\'t support any authentication methods. SASL problem?');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1188 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1189 if (!$this->_capability['sasl']) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1190 return $this->_pear->raiseError('This server doesn\'t support any authentication methods.');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1191 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1192
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1193 if ($userMethod) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1194 if (in_array($userMethod, $this->_capability['sasl'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1195 return $userMethod;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1196 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1197
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1198 $msg = 'No supported authentication method found. The server supports these methods: %s, but we want to use: %s';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1199 return $this->_pear->raiseError(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1200 sprintf($msg, implode(', ', $this->_capability['sasl']), $userMethod)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1201 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1202 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1203
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1204 foreach ($this->supportedAuthMethods as $method) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1205 if (in_array($method, $this->_capability['sasl'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1206 return $method;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1207 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1208 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1209
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1210 $msg = 'No supported authentication method found. The server supports these methods: %s, but we only support: %s';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1211 return $this->_pear->raiseError(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1212 sprintf($msg, implode(', ', $this->_capability['sasl']), implode(', ', $this->supportedAuthMethods))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1213 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1214 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1215
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1216 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1217 * Starts a TLS connection.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1218 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1219 * @return boolean True on success, PEAR_Error on failure.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1220 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1221 function _startTLS()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1222 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1223 $res = $this->_doCmd('STARTTLS');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1224 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1225 return $res;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1226 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1227
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1228 if (isset($this->_options['ssl']['crypto_method'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1229 $crypto_method = $this->_options['ssl']['crypto_method'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1230 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1231 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1232 // There is no flag to enable all TLS methods. Net_SMTP
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1233 // handles enabling TLS similarly.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1234 $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1235 | @STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1236 | @STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1237 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1238
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1239 if (!stream_socket_enable_crypto($this->_sock->fp, true, $crypto_method)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1240 return $this->_pear->raiseError('Failed to establish TLS connection', 2);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1241 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1242
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1243 $this->_debug('STARTTLS negotiation successful');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1244
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1245 // The server should be sending a CAPABILITY response after
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1246 // negotiating TLS. Read it, and ignore if it doesn't.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1247 // Unfortunately old Cyrus versions are broken and don't send a
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1248 // CAPABILITY response, thus we would wait here forever. Parse the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1249 // Cyrus version and work around this broken behavior.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1250 if (!preg_match('/^CYRUS TIMSIEVED V([0-9.]+)/', $this->_capability['implementation'], $matches)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1251 || version_compare($matches[1], '2.3.10', '>=')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1252 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1253 $this->_doCmd();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1254 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1255
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1256 // Query the server capabilities again now that we are under
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1257 // encryption.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1258 $res = $this->_cmdCapability();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1259 if (is_a($res, 'PEAR_Error')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1260 return $this->_pear->raiseError(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1261 'Failed to connect, server said: ' . $res->getMessage(), 2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1262 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1263 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1264
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1265 return true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1266 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1267
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1268 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1269 * Returns the length of a string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1270 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1271 * @param string $string A string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1272 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1273 * @return integer The length of the string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1274 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1275 function _getLineLength($string)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1276 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1277 if (extension_loaded('mbstring')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1278 return mb_strlen($string, 'latin1');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1279 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1280 return strlen($string);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1281 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1282 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1283
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1284 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1285 * Locale independant strtoupper() implementation.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1286 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1287 * @param string $string The string to convert to lowercase.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1288 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1289 * @return string The lowercased string, based on ASCII encoding.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1290 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1291 function _toUpper($string)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1292 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1293 $language = setlocale(LC_CTYPE, 0);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1294 setlocale(LC_CTYPE, 'C');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1295 $string = strtoupper($string);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1296 setlocale(LC_CTYPE, $language);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1297 return $string;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1298 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1299
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1300 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1301 * Converts strings into RFC's quoted-string or literal-c2s form.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1302 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1303 * @param string $string The string to convert.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1304 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1305 * @return string Result string.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1306 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1307 function _escape($string)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1308 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1309 // Some implementations don't allow UTF-8 characters in quoted-string,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1310 // use literal-c2s.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1311 if (preg_match('/[^\x01-\x09\x0B-\x0C\x0E-\x7F]/', $string)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1312 return sprintf("{%d+}\r\n%s", $this->_getLineLength($string), $string);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1313 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1314
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1315 return '"' . addcslashes($string, '\\"') . '"';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1316 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1317
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1318 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1319 * Write debug text to the current debug output handler.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1320 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1321 * @param string $message Debug message text.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1322 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1323 * @return void
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1324 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1325 function _debug($message)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1326 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1327 if ($this->_debug) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1328 if ($this->_debug_handler) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1329 call_user_func_array($this->_debug_handler, array(&$this, $message));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1330 } else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1331 echo "$message\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1332 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1333 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1334 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1335 }