From 03dbf37d5cfe46ad0441f9916e6f22d5de20bcab Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sun, 08 Aug 2010 07:39:19 -0400
Subject: [PATCH] - Small improvement in SELECT response parsing

---
 program/include/rcube_imap_generic.php |   21 +++++++--------------
 1 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index 3a44b3b..de57671 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -749,31 +749,24 @@
 
 	    if ($this->putLine("sel1 SELECT \"".$this->escape($mailbox).'"')) {
 		    do {
-			    $line = rtrim($this->readLine(300));
-			    $a = explode(' ', $line);
-			    if (count($a) == 3) {
-				    $token = strtoupper($a[2]);
-				    if ($token == 'EXISTS') {
-					    $this->exists = (int) $a[1];
-				    }
-				    else if ($token == 'RECENT') {
-					    $this->recent = (int) $a[1];
-				    }
+			    $line = rtrim($this->readLine(512));
+
+			    if (preg_match('/^\* ([0-9]+) (EXISTS|RECENT)$/', $line, $m)) {
+			        $token = strtolower($m[2]);
+			        $this->$token = (int) $m[1];
 			    }
 			    else if (preg_match('/\[?PERMANENTFLAGS\s+\(([^\)]+)\)\]/U', $line, $match)) {
 				    $this->permanentflags = explode(' ', $match[1]);
 			    }
 		    } while (!$this->startsWith($line, 'sel1', true, true));
 
-		    if (strcasecmp($a[1], 'OK') == 0) {
+            if ($this->parseResult($line) == 0) {
 			    $this->selected = $mailbox;
 			    return true;
 		    }
-            else {
-                $this->error = "Couldn't select $mailbox";
-            }
 	    }
 
+        $this->error = "Couldn't select $mailbox";
         return false;
     }
 

--
Gitblit v1.9.1