Fix mixed use of message ID list (#2859)
authorpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 11 Jan 2022 09:07:59 +0000 (09:07 +0000)
committerpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 11 Jan 2022 09:07:59 +0000 (09:07 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@14936 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/imap_messages.php
src/read_body.php

index ad3e7863e7006c7c086ebd2768bfcdb88001e03c..27ca3a1d8f036b5113bb6653ca418dc49bacedf1 100755 (executable)
@@ -82,7 +82,8 @@ function sqimap_msgs_list_delete($imap_stream, $mailbox, $id, $bypass_trash=fals
 /**
  * Set a flag on the provided uid list
  * @param  resource imap connection
- * @param  array $id list with uid's
+ * @param  mixed $id Normally an array which is a list with message UIDs to be flagged
+ *                   or a string range such as "1:*"
  * @param  string $flag Flags to set/unset flags can be i.e.'\Seen', '\Answered', '\Seen \Answered'
  * @param  bool   $set  add (true) or remove (false) the provided flag
  * @param  bool   $handle_errors Show error messages in case of a NO, BAD or BYE response
@@ -92,8 +93,12 @@ function sqimap_toggle_flag($imap_stream, $id, $flag, $set, $handle_errors) {
     $msgs_id = sqimap_message_list_squisher($id);
     $set_string = ($set ? '+' : '-');
 
-    for ($i=0; $i<sizeof($id); $i++) {
-        $aMessageList["$id[$i]"] = array();
+    $aMessageList = array();
+    // TODO: There doesn't seem to be a reason to set up $aMessageList anyway because an empty array for each message doesn't add anything to the parseFetch() return value, so this code block could be simply deleted:
+    if (!is_string($id)) {
+        for ($i=0; $i<sizeof($id); $i++) {
+            $aMessageList["$id[$i]"] = array();
+        }
     }
 
     $aResponse = sqimap_run_command_list($imap_stream, "STORE $msgs_id ".$set_string."FLAGS ($flag)", $handle_errors, $response, $message, TRUE);
@@ -103,8 +108,8 @@ function sqimap_toggle_flag($imap_stream, $id, $flag, $set, $handle_errors) {
 
     // some broken IMAP servers do not return UID elements on UID STORE
     // if this is the case, then we need to do a UID FETCH
-    $testkey=$id[0];
-    if (!isset($parseFetchResults[$testkey]['UID'])) {
+    if (!empty($parseFetchResults)
+     && !isset(reset($parseFetchResults)['UID'])) {
         $aResponse = sqimap_run_command_list($imap_stream, "FETCH $msgs_id (FLAGS)", $handle_errors, $response, $message, TRUE);
         $parseFetchResults = parseFetch($aResponse,$aMessageList);
     }
index 3c3a70d8501c3e3e0c6b635e7ba965cac27a56be..68fbf46e9fef92acb0ebc1e3d9b3033399f5b3ef 100644 (file)
@@ -987,7 +987,7 @@ $header = $message->header;
 // they SHOULD be included as part of the FETCH responses."
 //
 if ($imap_server_type == 'gmail') {
-    sqimap_toggle_flag($imapConnection, $passed_id, '\\Seen', true, true);
+    sqimap_toggle_flag($imapConnection, array($passed_id), '\\Seen', true, true);
 }
 
 /****************************************/