|
Line 0
Link Here
|
|
|
1 |
--- Sieve.php.orig Sat Dec 17 17:48:27 2005 |
| 2 |
+++ Sieve.php Wed Jan 4 14:37:54 2006 |
| 3 |
@@ -331,7 +331,7 @@ |
| 4 |
* @param string $port Port of server |
| 5 |
* @return mixed True on success, PEAR_Error otherwise |
| 6 |
*/ |
| 7 |
- function connect($host, $port) |
| 8 |
+ function connect($host, $port, $options = null) |
| 9 |
{ |
| 10 |
if (NET_SIEVE_STATE_DISCONNECTED != $this->_state) { |
| 11 |
$msg='Not currently in DISCONNECTED state'; |
| 12 |
@@ -339,16 +339,16 @@ |
| 13 |
return $this->_raiseError($msg,$code); |
| 14 |
} |
| 15 |
|
| 16 |
- if (PEAR::isError($res = $this->_sock->connect($host, $port, null, 5))) { |
| 17 |
+ if (PEAR::isError($res = $this->_sock->connect($host, $port, null, 5, $options))) { |
| 18 |
return $res; |
| 19 |
} |
| 20 |
|
| 21 |
- |
| 22 |
$this->_state = NET_SIEVE_STATE_AUTHORISATION; |
| 23 |
if (PEAR::isError($res = $this->_doCmd())) { |
| 24 |
return $res; |
| 25 |
} |
| 26 |
- /* |
| 27 |
+ |
| 28 |
+ /* |
| 29 |
if(PEAR::isError($res = $this->_cmdCapability() )) { |
| 30 |
$msg='Failed to connect, server said: ' . $res->getMessage(); |
| 31 |
$code=2; |
| 32 |
@@ -358,6 +358,15 @@ |
| 33 |
// Get logon greeting/capability and parse |
| 34 |
$this->_parseCapability($res); |
| 35 |
|
| 36 |
+ // check if we can enable TLS via STARTTLS |
| 37 |
+ if($this->_capability['starttls'] == true && function_exists('stream_socket_enable_crypto') == true) |
| 38 |
+ {// begin enable TLS |
| 39 |
+ if (PEAR::isError($res = $this->_startTLS())) { |
| 40 |
+ return $res; |
| 41 |
+ } |
| 42 |
+ }// end enable TLS |
| 43 |
+ |
| 44 |
+ |
| 45 |
return true; |
| 46 |
} |
| 47 |
|
| 48 |
@@ -806,7 +815,7 @@ |
| 49 |
$data = preg_split('/\r?\n/', $data, -1, PREG_SPLIT_NO_EMPTY); |
| 50 |
|
| 51 |
for ($i = 0; $i < count($data); $i++) { |
| 52 |
- if (preg_match('/^"([a-z]+)" ("(.*)")?$/i', $data[$i], $matches)) { |
| 53 |
+ if (preg_match('/^"([a-z]+)"( "(.*)")?$/i', $data[$i], $matches)) { |
| 54 |
switch (strtolower($matches[1])) { |
| 55 |
case 'implementation': |
| 56 |
$this->_capability['implementation'] = $matches[3]; |
| 57 |
@@ -822,6 +831,7 @@ |
| 58 |
|
| 59 |
case 'starttls': |
| 60 |
$this->_capability['starttls'] = true; |
| 61 |
+ break; |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
@@ -946,8 +956,10 @@ |
| 66 |
if (preg_match('/^bye \(referral "(sieve:\/\/)?([^"]+)/i', $line, $matches)) { |
| 67 |
// Check for referral, then follow it. Otherwise, carp an error. |
| 68 |
//$this->_data['host'] = $matches[1]; |
| 69 |
- $this->_data['host'] = $matches[2]; |
| 70 |
- if (PEAR::isError($error = $this->_handleConnectAndLogin() ) ){ |
| 71 |
+ //$this->_data['host'] = $matches[2]; |
| 72 |
+ //replace the old host with the referral host preserving any protocol prefix |
| 73 |
+ $this->_data['host'] = preg_replace('/\w+(?!(\w|\:\/\/)).*/',$matches[2],$this->_data['host']); |
| 74 |
+ if (PEAR::isError($error = $this->_handleConnectAndLogin() ) ){ |
| 75 |
$msg="Can't follow referral to " . $this->_data['host'] . ", The error was= " . $error->getMessage() ; |
| 76 |
$code=5; |
| 77 |
return $this->_raiseError($msg,$code); |
| 78 |
@@ -1133,7 +1145,7 @@ |
| 79 |
|
| 80 |
|
| 81 |
/** |
| 82 |
- * Return true if tyhe server has that extension |
| 83 |
+ * Return true if the server has that extension |
| 84 |
* |
| 85 |
* @access public |
| 86 |
* @param string the extension to compare |
| 87 |
@@ -1157,9 +1169,32 @@ |
| 88 |
return false; |
| 89 |
} |
| 90 |
|
| 91 |
+ /** |
| 92 |
+ * Return true if the TLS negotiation was successful |
| 93 |
+ * |
| 94 |
+ * @access public |
| 95 |
+ * @return mixed true on success, PEAR_Error on failure |
| 96 |
+ */ |
| 97 |
+ function _startTLS() |
| 98 |
+ { |
| 99 |
+ if (PEAR::isError($res = $this->_doCmd("STARTTLS"))) { |
| 100 |
+ return $res; |
| 101 |
+ } |
| 102 |
+ |
| 103 |
+ if(stream_socket_enable_crypto($this->_sock->fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT) == false) { |
| 104 |
+ $msg='Failed to establish TLS connection'; |
| 105 |
+ $code=2; |
| 106 |
+ return $this->_raiseError($msg,$code); |
| 107 |
+ } |
| 108 |
|
| 109 |
- |
| 110 |
- |
| 111 |
+ // RFC says we need to query the server capabilities again |
| 112 |
+ if(PEAR::isError($res = $this->_cmdCapability() )) { |
| 113 |
+ $msg='Failed to connect, server said: ' . $res->getMessage(); |
| 114 |
+ $code=2; |
| 115 |
+ return $this->_raiseError($msg,$code); |
| 116 |
+ } |
| 117 |
+ return true; |
| 118 |
+ } |
| 119 |
|
| 120 |
} |
| 121 |
-?> |
| 122 |
\ No newline at end of file |
| 123 |
+?> |