quick hack to remove the preg_match for * [0-9]+ FETCH in case of
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 26 Aug 2002 09:27:43 +0000 (09:27 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 26 Aug 2002 09:27:43 +0000 (09:27 +0000)
sqimap_run_command. Explanation: if we request for a single fetch (not a
list) we shouldn't look for extra fetch lines because this stops the
processing in case of body entities with * a001 fetch lines.
Later we can glue the 2 functions together if we add information to
sqimap_read_data_list about the nature of the call (list or not)

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3458 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/imap_general.php

index 11586a1853888a134669a487fa59ffbba099aad1..4cc799422a94932d084a8bc4d2226456a0128ad6 100755 (executable)
@@ -87,10 +87,11 @@ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors, &$response,
             case preg_match("/^\* (OK \[PARSE\])(.*)$/", $read):
                 $read = sqimap_fgets($imap_stream);
                 break 1;
             case preg_match("/^\* (OK \[PARSE\])(.*)$/", $read):
                 $read = sqimap_fgets($imap_stream);
                 break 1;
-            case preg_match('/^\* [0-9]+ FETCH.*/', $read):
+            case preg_match('/^\* ([0-9]+) FETCH.*/', $read, $regs):
                 $fetch_data = array();
                 $fetch_data[] = $read;
                 $read = sqimap_fgets($imap_stream);
                 $fetch_data = array();
                 $fetch_data[] = $read;
                 $read = sqimap_fgets($imap_stream);
+                $i = 0;
                 while (!preg_match('/^\* [0-9]+ FETCH.*/', $read) && 
                        !preg_match("/^$pre (OK|BAD|NO)(.*)$/", $read)) {
                     $fetch_data[] = $read;
                 while (!preg_match('/^\* [0-9]+ FETCH.*/', $read) && 
                        !preg_match("/^$pre (OK|BAD|NO)(.*)$/", $read)) {
                     $fetch_data[] = $read;
@@ -144,8 +145,74 @@ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors, &$response,
 }
 
 function sqimap_read_data ($imap_stream, $pre, $handle_errors, &$response, &$message, $query = '') {
 }
 
 function sqimap_read_data ($imap_stream, $pre, $handle_errors, &$response, &$message, $query = '') {
-    $res = sqimap_read_data_list($imap_stream, $pre, $handle_errors, $response, $message, $query);
-    return $res[0];
+    global $color, $squirrelmail_language;
+    $read = '';
+    $pre_a = explode(' ',trim($pre));
+    $pre = $pre_a[0];
+    $result = '';
+    $data = array();
+    $read = sqimap_fgets($imap_stream);
+    while (1) {
+        switch (true) { 
+            case preg_match("/^$pre (OK|BAD|NO)(.*)$/", $read, $regs):
+            case preg_match('/^\* (BYE \[ALERT\])(.*)$/', $read, $regs):
+                $response = $regs[1];
+                $message = trim($regs[2]);
+                break 2;
+            case preg_match("/^\* (OK \[PARSE\])(.*)$/", $read):
+                $read = sqimap_fgets($imap_stream);
+                break 1;
+            case preg_match('/^\* [0-9]+ FETCH.*/', $read):
+                $fetch_data = array();
+                $fetch_data[] = $read;
+                $read = sqimap_fgets($imap_stream);
+                while (!preg_match("/^$pre (OK|BAD|NO)(.*)$/", $read)) {
+                    $fetch_data[] = $read;
+                    $read = sqimap_fgets($imap_stream);
+                }
+                $result = $fetch_data;
+               break 2;
+            default:
+                $data[] = $read;
+                $read = sqimap_fgets($imap_stream);
+                break 1;
+        }
+    }
+    if (!empty($data)) {
+        $result = $data;
+    }
+    if ($handle_errors == false) {
+        return( $result );
+    } 
+    elseif ($response == 'NO') {
+    /* ignore this error from M$ exchange, it is not fatal (aka bug) */
+        if (strstr($message, 'command resulted in') === false) {
+            set_up_language($squirrelmail_language);
+            echo "<br><b><font color=$color[2]>\n" .
+                _("ERROR : Could not complete request.") .
+                "</b><br>\n" .
+                _("Query:") .
+                $query . '<br>' .
+                _("Reason Given: ") .
+                $message . "</font><br>\n";
+            exit;
+        }
+    } 
+    elseif ($response == 'BAD') {
+        set_up_language($squirrelmail_language);
+        echo "<br><b><font color=$color[2]>\n" .
+            _("ERROR : Bad or malformed request.") .
+            "</b><br>\n" .
+            _("Query:") .
+            $query . '<br>' .
+            _("Server responded: ") .
+            $message . "</font><br>\n";
+        exit;
+    } 
+    else {
+        return $result;
+    }
+
 }
 
 /*
 }
 
 /*