Optimization:
[squirrelmail.git] / functions / imap_mailbox.php
index fe275a1ecedbe35188c965d8c795a70f1908642f..f6c8d42ac6daf858ed1656115e0cc547d49088e4 100755 (executable)
 
 global $boxesnew;
 
+/**
+ * If $haystack is a full mailbox name, and $needle is the mailbox
+ * separator character, returns the second last part of the full
+ * mailbox name (i.e. the mailbox's parent mailbox)
+ */
+function readMailboxParent($haystack, $needle) {
+
+    if ($needle == '') {
+        $ret = '';
+    } else {
+        $parts = explode($needle, $haystack);
+        $elem = array_pop($parts);
+        while ($elem == '' && count($parts)) {
+            $elem = array_pop($parts);
+        }
+        $ret = join($needle, $parts);
+    }
+    return( $ret );
+}
+
+
 function isBoxBelow( $box2, $box1 ) {
     global $delimiter, $folder_prefix, $imap_server_type;
 
@@ -468,7 +489,12 @@ function sqimap_mailbox_list($imap_stream) {
                     $used[$k] = true;
                 }
                 $spec_sub = str_replace(' ', '', $box['formatted']);
-                if (!$used[$k] && preg_match("/^$default_folder_prefix(Sent|Drafts|Trash).{1}$spec_sub$/", $box['unformatted']) ) {
+
+               /* In case of problems with preg
+                  here is a ereg version
+                 if (!$used[$k] && ereg("^$default_folder_prefix(Sent|Drafts|Trash).{1}$spec_sub$", $box['unformatted']) ) { */
+                 
+                if (!$used[$k] && preg_match("?^$default_folder_prefix(Sent|Drafts|Trash).{1}$spec_sub$?", $box['unformatted']) ) {
                     $boxesnew[] = $box;
                     $used[$k] = true;
                 }