* Request UID and UIDVALIDITY from the status response if not available in the
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 19 May 2004 22:36:41 +0000 (22:36 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 19 May 2004 22:36:41 +0000 (22:36 +0000)
  select response.
* Tried to fix the broken del move next function and added a few arguments
  to the dmn_expunge function because the globals scared me when I couldn't
  get the job done.

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

functions/imap_general.php
functions/imap_mailbox.php
functions/mailbox_display.php
src/read_body.php
src/right_main.php

index 73f6d619d3b9ef76d7fb881bbb013f107450aad5..05880e12516e772ae47663bc21b280a8a099f886 100755 (executable)
@@ -1039,27 +1039,26 @@ function parseAddress($address, $max=0) {
 
 /**
  * Returns the number of unseen messages in this folder.
+ * obsoleted by sqimap_status_messages !
  */
 function sqimap_unseen_messages ($imap_stream, $mailbox) {
-    $read_ary = sqimap_run_command ($imap_stream, 'STATUS ' . sqimap_encode_mailbox_name($mailbox) . ' (UNSEEN)', false, $result, $message);
-    $i = 0;
-    $regs = array(false, false);
-    while (isset($read_ary[$i])) {
-        if (ereg("UNSEEN ([0-9]+)", $read_ary[$i], $regs)) {
-            break;
-        }
-        $i++;
-    }
-    return $regs[1];
+    $aStatus = sqimap_status_messages($imap_stream,$mailbox,array('UNSEEN'));
+    return $aStatus['UNSEEN'];
 }
 
 /**
- * Returns the number of total/unseen/recent messages in this folder
+ * Returns the status items of a mailbox.
+ * Default it returns MESSAGES,UNSEEN and RECENT
+ * Supported status items are MESSAGES, UNSEEN, RECENT, UIDNEXT and UIDVALIDITY
  */
-function sqimap_status_messages ($imap_stream, $mailbox) {
-    $read_ary = sqimap_run_command ($imap_stream, 'STATUS ' . sqimap_encode_mailbox_name($mailbox) . ' (MESSAGES UNSEEN RECENT)', false, $result, $message);
+function sqimap_status_messages ($imap_stream, $mailbox, 
+                       $aStatusItems = array('MESSAGES','UNSEEN','RECENT')) {
+
+    $aStatusItems = implode(' ',$aStutusItems);
+    $read_ary = sqimap_run_command ($imap_stream, 'STATUS ' . sqimap_encode_mailbox_name($mailbox) .
+                                    " ($aStatusItems)", false, $result, $message);
     $i = 0;
-    $messages = $unseen = $recent = false;
+    $messages = $unseen = $recent = $uidnext = $uidvalidity = false;
     $regs = array(false,false);
     while (isset($read_ary[$i])) {
         if (preg_match('/UNSEEN\s+([0-9]+)/i', $read_ary[$i], $regs)) {
@@ -1071,9 +1070,19 @@ function sqimap_status_messages ($imap_stream, $mailbox) {
         if (preg_match('/RECENT\s+([0-9]+)/i', $read_ary[$i], $regs)) {
             $recent = $regs[1];
         }        
+        if (preg_match('/UIDNEXT\s+([0-9]+)/i', $read_ary[$i], $regs)) {
+            $uidnext = $regs[1];
+        }        
+        if (preg_match('/UIDVALIDITY\s+([0-9]+)/i', $read_ary[$i], $regs)) {
+            $uidvalidity = $regs[1];
+        }        
         $i++;
     }
-    return array('MESSAGES' => $messages, 'UNSEEN'=>$unseen, 'RECENT' => $recent);
+    return array('MESSAGES' => $messages, 
+                 'UNSEEN'=>$unseen, 
+                 'RECENT' => $recent,
+                 'UIDNEXT' => $uidnext,
+                 'UIDVALIDITY' => $uidvalidity);
 }
 
 
index a3b419571611e5e32808bbf5f8158c7cc2a59312..51149e30ac84850fb571522ea60ced721448707b 100755 (executable)
@@ -257,14 +257,17 @@ function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true,
  * won't be changed - the array element for the message
  * will just be removed.
  */
-function sqimap_mailbox_expunge_dmn($message_id)
+function sqimap_mailbox_expunge_dmn($message_id, $aMbxResponse, &$server_sort_array)
 {
     global $msgs, $msort, $sort, $imapConnection, 
-           $mailbox, $mbx_response, $auto_expunge, 
+           $mailbox, $auto_expunge, 
            $sort, $allow_server_sort, $thread_sort_messages, $allow_thread_sort,
            $username, $data_dir;
     $cnt = 0;
 
+    if (!isset($sort) || $sort === false) {
+        sqgetGlobalVar('sort',$sort,SQ_GET);
+    }
     // Got to grab this out of prefs, since it isn't saved from mailbox_view.php
     if ($allow_thread_sort) {
         $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox",0); 
@@ -290,26 +293,32 @@ function sqimap_mailbox_expunge_dmn($message_id)
 
     if ($auto_expunge) {
          $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
+    } else {
+         return $cnt;
     }
 
     // And after all that mucking around, update the sort list!
     // Remind me why the hell we need those two arrays again?!
 
-    sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
-
-
     if ( $allow_thread_sort && $thread_sort_messages ) {
         $server_sort_array = get_thread_sort($imapConnection);
     } elseif ( $allow_server_sort ) {
-        $key = array_search($message_id,$server_sort_array,true);
-        if ($key !== false) {
-           unset($server_sort_array[$key]);
-           $server_sort_array = array_values($server_sort_array);
+        if (is_array($server_sort_array)) { 
+            $key = array_search($message_id,$server_sort_array,true);
+            if ($key !== false) {
+                unset($server_sort_array[$key]);
+                $server_sort_array = array_values($server_sort_array);
+            } else {
+                $server_sort_array = sqimap_get_sort_order($imapConnection,$sort,$aMbxResponse);
+            }
+        } else {
+            $server_sort_array = sqimap_get_sort_order($imapConnection,$sort,$aMbxResponse);
         }
-     } else {
-        $server_sort_array = sqimap_get_php_sort_order($imapConnection, $mbx_response);
+    } else {
+        $server_sort_array = sqimap_get_php_sort_order($imapConnection,
+                                                   $sort,$aMbxResponse);
     }
-    sqsession_register('server_sort_array',$server_sort_array);
+    sqsession_register($server_sort_array,'server_sort_array');
     return $cnt;
 }
 
index 9eee288791d27d4ec872814a9aadf1bfeabb74bc..48fbb31397207c309e393ce49fbfa509a3fda9f8 100644 (file)
@@ -460,7 +460,7 @@ function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
  */
 function getServerSortMessages($imapConnection, $start_msg, $show_num,
                                $num_msgs, $server_sort_order, $mbxresponse) {
-    if (isset($mbxresponse['SORT_ARRAY']) && $mbxresponse['SORT_ARRAY']) {
+    if (isset($mbxresponse['SORT_ARRAY']) && is_array($mbxresponse['SORT_ARRAY'])) {
         $id = $mbxresponse['SORT_ARRAY'];
     } else {
         $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
index 77f34d873e47f805811365095a3c1ff5ce48251e..99cb4ce8a7e2a340146eafabc900522c88fa8065 100644 (file)
@@ -830,8 +830,7 @@ $mbx_response   = sqimap_mailbox_select($imapConnection, $mailbox, false, false,
  */
 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
     sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
-
-    sqimap_mailbox_expunge_dmn($delete_id);
+    sqimap_mailbox_expunge_dmn($delete_id,$mbx_response,$server_sort_array);
 }
 
 /**
@@ -844,7 +843,7 @@ $uidvalidity = $mbx_response['UIDVALIDITY'];
 if (!isset($messages[$uidvalidity])) {
    $messages[$uidvalidity] = array();
 }
-if (!isset($messages[$uidvalidity][$passed_id])) {
+if (!isset($messages[$uidvalidity][$passed_id]) || $delete_id) {
    $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
    $FirstTimeSee = !$message->is_seen;
    $message->is_seen = true;
index b07aec7af8e5071fae44fee3375e2ec8482fd7a4..e3d5a5055fea80ded01322b78ea92532f59bf6f9 100644 (file)
@@ -156,17 +156,29 @@ $aMbxResponse['SORT_ARRAY'] = false;
 
 sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION);
 
+// deal with imap servers that do not return the required UIDNEXT or
+// UIDVALIDITY response
+// from a SELECT call (since rfc 3501 it's required)
+if (!isset($aMbxResponse['UIDNEXT']) || !isset($aMbxResponse['UIDVALIDITY'])) {
+    $aStatus = sqimap_status_messages($imapConnection,$mailbox,
+                                      array('UIDNEXT','UIDVALIDITY'));
+    $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT'];
+    $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY'];
+}
+
 if ($aLastSelectedMailbox && !isset($newsort)) {
-  // check if we deal with the same mailbox
-  if ($aLastSelectedMailbox['NAME'] == $mailbox) {
-     if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
-         $aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
-         $aLastSelectedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT']) {
-         // sort is still valid
-         sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
-         $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
-     }
-  } 
+    // check if we deal with the same mailbox
+    if ($aLastSelectedMailbox['NAME'] == $mailbox) {
+       if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
+           $aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
+           $aLastSelectedMailbox['UIDNEXT']  == $aMbxResponse['UIDNEXT']) {
+           // sort is still valid
+           sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
+           if ($server_sort_array && is_array($server_sort_array)) {
+               $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
+           }
+       }
+    } 
 }
  
 $aLastSelectedMailbox['NAME'] = $mailbox;