From c6f5adbac33e5a14cce5c093b2b9e69ec39a52c6 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 29 Apr 2013 13:32:29 +0200 Subject: Fix handling untagged responses in IMAP FETCH - "could not load message" error (#1489074) --- program/lib/Roundcube/rcube_imap_generic.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'program/lib/Roundcube/rcube_imap_generic.php') diff --git a/program/lib/Roundcube/rcube_imap_generic.php b/program/lib/Roundcube/rcube_imap_generic.php index 460e6cc92..db50ffbab 100644 --- a/program/lib/Roundcube/rcube_imap_generic.php +++ b/program/lib/Roundcube/rcube_imap_generic.php @@ -2475,6 +2475,7 @@ class rcube_imap_generic $key = $this->nextTag(); $request = $key . ($is_uid ? ' UID' : '') . " FETCH $id ($fetch_mode.PEEK[$part]$partial)"; $result = false; + $found = false; // send request if (!$this->putLine($request)) { @@ -2494,18 +2495,25 @@ class rcube_imap_generic break; } - if (!preg_match('/^\* ([0-9]+) FETCH (.*)$/', $line, $m)) { + // skip irrelevant untagged responses (we have a result already) + if ($found || !preg_match('/^\* ([0-9]+) FETCH (.*)$/', $line, $m)) { continue; } $line = $m[2]; - $last = substr($line, -1); // handle one line response - if ($line[0] == '(' && $last == ')') { + if ($line[0] == '(' && substr($line, -1) == ')') { // tokenize content inside brackets - $tokens = $this->tokenizeResponse(preg_replace('/(^\(|\$)/', '', $line)); - $result = count($tokens) == 1 ? $tokens[0] : false; + $tokens = $this->tokenizeResponse(preg_replace('/(^\(|\)$)/', '', $line)); + + for ($i=0; $i 0) { $line = $this->readLine(8192); -- cgit v1.2.3