More rg=0
[squirrelmail.git] / functions / imap_mailbox.php
index 44e14a91dca65f3f059282464b1c757646f83299..b220ee6f6042818d0f4b56b9fc7957b30a1aa4d4 100755 (executable)
@@ -10,8 +10,8 @@
  *
  * $Id$
  */
-require_once('../functions/imap_utf7_encode_local.php');
-require_once('../functions/imap_utf7_decode_local.php');
+require_once(SM_PATH . 'functions/imap_utf7_encode_local.php');
+require_once(SM_PATH . 'functions/imap_utf7_decode_local.php');
 global $boxesnew;
 
 class mailboxes {
@@ -75,13 +75,15 @@ function sortSpecialMbx($a, $b) {
     return ($acmp>$bcmp) ? 1: -1;
 }      
 
-
 function find_mailbox_name ($mailbox) {
     if (ereg(" *\"([^\r\n\"]*)\"[ \r\n]*$", $mailbox, $regs))
         return $regs[1];
     ereg(" *([^ \r\n\"]*)[ \r\n]*$",$mailbox,$regs);
     return $regs[1];
-    
+}
+
+function check_is_noselect ($lsub_line) {
+    return preg_match("/^\* LSUB \([^\)]*\\Noselect[^\)]*\)/i", $lsub_line);
 }
 
 /**
@@ -148,20 +150,26 @@ function isSpecialMailbox( $box ) {
 
 /* Expunges a mailbox */
 function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, $id='') {
-  global $uid_support;
-    if (isset($id)) {
+    global $uid_support;
+    if ($id) {
        if (is_array($id)) {
           $id = sqimap_message_list_squisher($id);
        }
        $id = ' '.$id;
+       $uid = $uid_support;
+    } else {
+       $uid = false;
     }
-    $read = sqimap_run_command($imap_stream, 'EXPUNGE$id', $handle_errors,
-                               $response, $message, $uid_support);
-    $cnt = 0;                         
-    foreach ($read as $r) {
-       if (pregmatch('/^\*\s[0-9]+\sEXPUNGE/AUi',$r,$regs)) {
-          $cnt++;
-       }
+    $read = sqimap_run_command($imap_stream, 'EXPUNGE'.$id, $handle_errors,
+                               $response, $message, $uid);
+    $cnt = 0;
+    
+    if ( is_array( $read ) ) {
+        foreach ($read as $r) {
+           if (preg_match('/^\*\s[0-9]+\sEXPUNGE/AUi',$r,$regs)) {
+              $cnt++;
+           }
+        }
     }
     return $cnt; 
 }
@@ -453,8 +461,8 @@ function sqimap_mailbox_list($imap_stream) {
         $inbox_in_list = false;
         $inbox_subscribed = false;
 
-        require_once('../src/load_prefs.php');
-        require_once('../functions/array.php');
+        require_once(SM_PATH . 'include/load_prefs.php');
+        require_once(SM_PATH . 'functions/array.php');
 
     if ($noselect_fix_enable) {
         $lsub_args = "LSUB \"$folder_prefix\" \"*%\"";
@@ -578,8 +586,7 @@ function sqimap_mailbox_list($imap_stream) {
                     $used[$k] = true;
                 }
                 $spec_sub = str_replace(' ', '', $box['formatted']);
-                $spec_sub = str_replace('*', '', $spec_sub);
-                $spec_sub = str_replace('?', '\?', $spec_sub);
+                $spec_sub = preg_replace("/(\*|\[|\]|\(|\)|\?|\+|\{|\}|\^|\\$)/", '\\\\'.'\\1', $spec_sub);
 
                /* In case of problems with preg
                   here is a ereg version
@@ -608,7 +615,7 @@ function sqimap_mailbox_list($imap_stream) {
 function sqimap_mailbox_list_all($imap_stream) {
     global $list_special_folders_first, $folder_prefix, $delimiter;
 
-    require_once('../functions/array.php');
+    require_once(SM_PATH . 'functions/array.php');
 
     $ssid = sqimap_session_id();
     $lsid = strlen( $ssid );
@@ -704,8 +711,8 @@ function sqimap_mailbox_tree($imap_stream) {
         $inbox_in_list = false;
         $inbox_subscribed = false;
 
-        require_once('../src/load_prefs.php');
-        require_once('../functions/array.php');
+        require_once(SM_PATH . 'include/load_prefs.php');
+        require_once(SM_PATH . 'functions/array.php');
 
         /* LSUB array */
         $lsub_ary = sqimap_run_command ($imap_stream, "LSUB \"$folder_prefix\" \"*\"",
@@ -735,10 +742,11 @@ function sqimap_mailbox_tree($imap_stream) {
 //             $sorted_lsub_ary[] = array ('mbx' => $mbx, 'flag' => $flag); 
 //         }
            $mbx = find_mailbox_name($lsub_ary[$i]);
+           $noselect = check_is_noselect($lsub_ary[$i]);
            if (substr($mbx, -1) == $delimiter) {
                $mbx = substr($mbx, 0, strlen($mbx) - 1);
            }
-           $sorted_lsub_ary[] = array ('mbx' => $mbx, 'flag' => ''); 
+           $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect); 
         }
        array_multisort($sorted_lsub_ary, SORT_ASC, SORT_REGULAR);
 
@@ -787,13 +795,19 @@ function sqimap_mailbox_tree($imap_stream) {
            if (($unseen_notify == 2 && $mbx == 'INBOX') 
                || $unseen_notify == 3 
                || ($move_to_trash && ($mbx == $trash_folder))) {
-               $sorted_lsub_ary[$i]['unseen'] = sqimap_unseen_messages($imap_stream, $mbx);
+               $sorted_lsub_ary[$i]['unseen'] = 
+                       $sorted_lsub_ary[$i]['noselect'] ?
+                           0 : sqimap_unseen_messages($imap_stream, $mbx);
                if ($unseen_type == 2 || ($move_to_trash 
                    && ($mbx == $trash_folder) )) {
-                   $sorted_lsub_ary[$i]['nummessages'] = sqimap_get_num_messages($imap_stream, $mbx);
+                    $sorted_lsub_ary[$i]['nummessages'] =
+                       $sorted_lsub_ary[$i]['noselect'] ?
+                           0 : sqimap_get_num_messages($imap_stream, $mbx);
                }
                if ($mbx == $trash_folder) {
-                   $sorted_lsub_ary[$i]['nummessages'] = sqimap_get_num_messages($imap_stream, $mbx);
+                    $sorted_lsub_ary[$i]['nummessages'] =
+                       $sorted_lsub_ary[$i]['noselect'] ?
+                           0 : sqimap_get_num_messages($imap_stream, $mbx);
                }           
            }
        }
@@ -856,6 +870,8 @@ function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false) {
            if (isset($mbx_ary[$i]['nummessages'])) {
                $mbx->total = $mbx_ary[$i]['nummessages'];
            }
+
+           $mbx->is_noselect = $mbx_ary[$i]['noselect'];
            
             $r_del_pos = strrpos($mbx_ary[$i]['mbx'], $delimiter);
            if ($r_del_pos) {