[Svn] r4471 - trunk/plugins/managesieve/lib/Net

trac at roundcube.net trac at roundcube.net
Sun Jan 30 20:43:26 CET 2011


Author: alec
Date: 2011-01-30 13:43:26 -0600 (Sun, 30 Jan 2011)
New Revision: 4471

Modified:
   trunk/plugins/managesieve/lib/Net/Sieve.php
Log:
- Improvements in string literals handling


Modified: trunk/plugins/managesieve/lib/Net/Sieve.php
===================================================================
--- trunk/plugins/managesieve/lib/Net/Sieve.php	2011-01-30 14:52:37 UTC (rev 4470)
+++ trunk/plugins/managesieve/lib/Net/Sieve.php	2011-01-30 19:43:26 UTC (rev 4471)
@@ -763,7 +763,7 @@
             return $res;
         }
 
-        return preg_replace('/{[0-9]+}\r\n/', '', $res);
+        return preg_replace('/^{[0-9]+}\r\n/', '', $res);
     }
 
     /**
@@ -981,6 +981,28 @@
     }
 
     /**
+     * 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 @@
 
                 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 @@
                     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

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list