Code Cleaning
[squirrelmail.git] / functions / imap_mailbox.php
index 3b0dfdd119361b6369244a2facac0bbb15f1c13e..375b97bfee4262691b5e23d3750cf131d60af45e 100755 (executable)
  * $Id$
  */
 
+function isBoxBelow( $box2, $box1 ) {
+
+    global $delimiter, $folder_prefix, $imap_server_type;
+
+    if ( $imap_server_type == 'uw' ) {
+        $boxs = $box2;
+        $i = strpos( $box1, $delimiter, strlen( $folder_prefix ) );
+        if ( $i === FALSE ) {
+            $i = strlen( $box2 );
+        }
+    } else {
+        $boxs = $box2 . $delimiter;
+        // Skip next second delimiter
+        $i = strpos( $box1, $delimiter );
+        $i = strpos( $box1, $delimiter, $i + 1  );
+        if ( $i === FALSE ) {
+            $i = strlen( $box2 );
+        } else {
+            $i++;
+        }
+    }
+
+    return( substr( $box1, 0, $i ) == substr( $boxs, 0, $i ) );
+
+}
+
 /*
     Defines Special Mail Boxes
 */
-
 function isSpecialMailbox( $box ) {
 
     global $trash_folder, $sent_folder, $draft_folder,
-           $move_to_trash, $move_to_sent, $save_as_draft,
-           $delimiter, $folder_prefix;
-
-    $i = strpos( $sent_folder, $delimiter, strlen( $folder_prefix ) );
+           $move_to_trash, $move_to_sent, $save_as_draft;
 
     $ret = ( (strtolower($box) == 'inbox') ||
-             ($box == $trash_folder &&
-              $move_to_trash) ||
-             (substr( $sent_folder, 0, max( $i, strlen( $box ) ) ) == $box &&
-              $move_to_sent) ||
-             ($box == $draft_folder &&
-              $save_as_draft) );
+             ( $move_to_trash && isBoxBelow( $box, $trash_folder ) ) ||
+             ( $move_to_sent && isBoxBelow( $box, $sent_folder )) ||
+             ($save_as_draft && $box == $draft_folder ) );
 
     return( $ret );
 
@@ -337,13 +356,13 @@ function user_strcasecmp($a, $b) {
  **  See comment on sqimap_mailbox_parse() for info about the returned array.
  ******************************************************************************/
 function sqimap_mailbox_list ($imap_stream) {
+
     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;
 
-    $inbox_in_list = false;
-    $inbox_subscribed = false;
+    $inbox_in_list = $inbox_subscribed = FALSE;
 
     require_once('../src/load_prefs.php');
     require_once('../functions/array.php');
@@ -475,6 +494,7 @@ function sqimap_mailbox_list ($imap_stream) {
     }
 
     return( $boxesnew );
+
 }
 
 /*
@@ -485,9 +505,7 @@ function sqimap_mailbox_list_all ($imap_stream)
     global $list_special_folders_first, $folder_prefix;
     global $delimiter;
 
-    if (!function_exists('ary_sort')) {
-        include_once('../functions/array.php');
-    }
+    require_once('../functions/array.php');
 
     $ssid = sqimap_session_id();
     $lsid = strlen( $ssid );
@@ -509,7 +527,7 @@ function sqimap_mailbox_list_all ($imap_stream)
         if (substr($read_ary[$i], 0, $lsid) != $ssid ) {
 
             /* Store the raw IMAP reply */
-            $boxes[$g]["raw"] = $read_ary[$i];
+            $boxes[$g]['raw'] = $read_ary[$i];
 
             /* Count number of delimiters ($delimiter) in folder name */
             $mailbox = find_mailbox_name($read_ary[$i]);