phpdoc block
[squirrelmail.git] / functions / imap_mailbox.php
index d9868748600fe8d53815cda155af8d2e48115015..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;
 }
 
@@ -626,16 +635,25 @@ function sqimap_mailbox_list($imap_stream, $force=false) {
         global $data_dir, $username, $list_special_folders_first,
                $folder_prefix, $trash_folder, $sent_folder, $draft_folder,
                $move_to_trash, $move_to_sent, $save_as_draft,
-               $delimiter, $noselect_fix_enable;
+               $delimiter, $noselect_fix_enable, $imap_server_type;
         $inbox_in_list = false;
         $inbox_subscribed = false;
+        $listsubscribed = sqimap_capability($imap_stream,'LIST-SUBSCRIBED');
 
         require_once(SM_PATH . 'include/load_prefs.php');
 
+
+        if ($listsubscribed) {
+            $lsub = 'LIST (SUBSCRIBED)';
+        } else {
+            $lsub = 'LSUB';
+        } 
+        
         if ($noselect_fix_enable) {
-            $lsub_args = "LSUB \"$folder_prefix\" \"*%\"";
+            
+            $lsub_args = "$lsub \"$folder_prefix\" \"*%\"";
         } else {
-            $lsub_args = "LSUB \"$folder_prefix\" \"*\"";
+            $lsub_args = "$lsub \"$folder_prefix\" \"*\"";
         }
         /* LSUB array */
         $lsub_ary = sqimap_run_command ($imap_stream, $lsub_args,
@@ -664,7 +682,8 @@ function sqimap_mailbox_list($imap_stream, $force=false) {
            * in other words, we cannot rely on it.
          */
         $sorted_list_ary = array();
-        for ($i=0; $i < count($sorted_lsub_ary); $i++) {
+ //       if (!$listsubscribed) {
+          for ($i=0; $i < count($sorted_lsub_ary); $i++) {
             if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
                 $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i])-1);
             }
@@ -682,7 +701,8 @@ function sqimap_mailbox_list($imap_stream, $force=false) {
             } else {
                 $sorted_list_ary[$i] = '';
             }
-        }
+          }
+ //       }
         /*
          * Just in case they're not subscribed to their inbox,
          * we'll get it for them anyway
@@ -800,7 +820,7 @@ function sqimap_mailbox_list_all($imap_stream) {
 
 function sqimap_mailbox_tree($imap_stream) {
     global $boxesnew, $default_folder_prefix, $unseen_notify, $unseen_type;
-    if (!isset($boxesnew)) {
+    if (true) {
 
         global $data_dir, $username, $list_special_folders_first,
                $folder_prefix, $delimiter, $trash_folder, $move_to_trash,