summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-01-30 19:43:26 +0000
committeralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2011-01-30 19:43:26 +0000
commitba0a963c2962bf887f26bcdbf95089b7cb636488 (patch)
tree6dfffbd9c3e11230b00361a51b252992c0c45eaa
parent964a2f0498fa498ed2b4726b988e48d3edaf79c7 (diff)
- Improvements in string literals handling
git-svn-id: https://svn.roundcube.net/trunk@4471 208e9e7b-5314-0410-a742-e7e81cd9613c
-rw-r--r--plugins/managesieve/lib/Net/Sieve.php47
1 files changed, 31 insertions, 16 deletions
diff --git a/plugins/managesieve/lib/Net/Sieve.php b/plugins/managesieve/lib/Net/Sieve.php
index ecc907194..14989ff0b 100644
--- a/plugins/managesieve/lib/Net/Sieve.php
+++ b/plugins/managesieve/lib/Net/Sieve.php
@@ -763,7 +763,7 @@ class Net_Sieve
return $res;
}
- return preg_replace('/{[0-9]+}\r\n/', '', $res);
+ return preg_replace('/^{[0-9]+}\r\n/', '', $res);
}
/**
@@ -981,6 +981,28 @@ class Net_Sieve
}
/**
+ * Receives x bytes from the server.
+ *
+ * @param int $length Number of bytes to read
+ *
+ * @return string The server response.
+ */
+ function _recvBytes($length)
+ {
+ $response = '';
+ $response_length = 0;
+
+ while ($response_length < $length) {
+ $response .= $this->_sock->read($length - $response_length);
+ $response_length = $this->_getLineLength($response);
+ }
+
+ $this->_debug("S: " . rtrim($response));
+
+ return $response;
+ }
+
+ /**
* Send a command and retrieves a response from the server.
*
* @param string $cmd The command to send.
@@ -1013,11 +1035,11 @@ class Net_Sieve
if ('NO' == substr($uc_line, 0, 2)) {
// Check for string literal error message.
- if (preg_match('/^no {([0-9]+)\+?}/i', $line, $matches)) {
- $line .= str_replace(
- "\r\n", ' ', $this->_sock->read($matches[1] + 2)
- );
- $this->_debug("S: $line");
+ if (preg_match('/{([0-9]+)}$/i', $line, $matches)) {
+ $line = substr($line, 0, -(strlen($matches[1])+2))
+ . str_replace(
+ "\r\n", ' ', $this->_recvBytes($matches[1] + 2)
+ );
}
return PEAR::raiseError(trim($response . substr($line, 2)), 3);
}
@@ -1052,16 +1074,9 @@ class Net_Sieve
return PEAR::raiseError(trim($response . $line), 6);
}
- if (preg_match('/^{([0-9]+)\+?}/i', $line, $matches)) {
- // Matches String Responses.
- $str_size = $matches[1] + 2;
- $line = '';
- $line_length = 0;
- while ($line_length < $str_size) {
- $line .= $this->_sock->read($str_size - $line_length);
- $line_length = $this->_getLineLength($line);
- }
- $this->_debug("S: $line");
+ if (preg_match('/^{([0-9]+)}/i', $line, $matches)) {
+ // Matches literal string responses.
+ $line = $this->_recvBytes($matches[1] + 2);
if (!$auth) {
// Receive the pending OK only if we aren't