Selaa lähdekoodia

* Request UID and UIDVALIDITY from the status response if not available in the
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.

stekkel 21 vuotta sitten
vanhempi
commit
f510138349
5 muutettua tiedostoa jossa 70 lisäystä ja 41 poistoa
  1. 24 15
      functions/imap_general.php
  2. 21 12
      functions/imap_mailbox.php
  3. 1 1
      functions/mailbox_display.php
  4. 2 3
      src/read_body.php
  5. 22 10
      src/right_main.php

+ 24 - 15
functions/imap_general.php

@@ -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);
 }
 
 

+ 21 - 12
functions/imap_mailbox.php

@@ -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;
 }
 

+ 1 - 1
functions/mailbox_display.php

@@ -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);

+ 2 - 3
src/read_body.php

@@ -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;

+ 22 - 10
src/right_main.php

@@ -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;