+ }
+
+ if ($has_inbox == false) {
+ $lsub_ary[] = '* LSUB () NIL INBOX';
+ }
+
+ /*
+ * Section about removing the last element was removed
+ * We don't return "* OK" anymore from sqimap_read_data
+ */
+
+ $sorted_lsub_ary = array();
+ $cnt = count($lsub_ary);
+ for ($i = 0; $i < $cnt; $i++) {
+ $mbx = find_mailbox_name($lsub_ary[$i]);
+
+ // only do the noselect test if !uw, is checked later. FIX ME see conf.pl setting
+ if ($imap_server_type != "uw") {
+ $noselect = check_is_noselect($lsub_ary[$i]);
+ $noinferiors = check_is_noinferiors($lsub_ary[$i]);
+ }
+ if (substr($mbx, -1) == $delimiter) {
+ $mbx = substr($mbx, 0, strlen($mbx) - 1);
+ }
+ $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
+ }
+ // FIX ME this requires a config setting inside conf.pl instead of checking on server type
+ if ($imap_server_type == "uw") {
+ $aQuery = array();
+ $aTag = array();
+ // prepare an array with queries
+ foreach ($sorted_lsub_ary as $aMbx) {
+ $mbx = stripslashes($aMbx['mbx']);
+ sqimap_prepare_pipelined_query('LIST "" ' . sqimap_encode_mailbox_name($mbx), $tag, $aQuery, false);
+ $aTag[$tag] = $mbx;
+ }
+ $sorted_lsub_ary = array();
+ // execute all the queries at once
+ $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
+ foreach($aTag as $tag => $mbx) {
+ if ($aServerResponse[$tag] == 'OK') {
+ $sResponse = implode('', $aResponse[$tag]);
+ $noselect = check_is_noselect($sResponse);
+ $noinferiors = check_is_noinferiors($sResponse);
+ $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
+ }
+ }
+ $cnt = count($sorted_lsub_ary);
+ }
+ $sorted_lsub_ary = array_values($sorted_lsub_ary);
+ array_multisort($sorted_lsub_ary, SORT_ASC, SORT_REGULAR);
+ $boxesnew = sqimap_fill_mailbox_tree($sorted_lsub_ary,false,$imap_stream);
+ return $boxesnew;
+ }
+}
+
+function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$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, $imap_server_type;
+
+ $special_folders = array ('INBOX', $sent_folder, $draft_folder, $trash_folder);
+
+ /* create virtual root node */
+ $mailboxes= new mailboxes();
+ $mailboxes->is_root = true;
+ $trail_del = false;
+ $start = 0;
+
+
+ if (isset($folder_prefix) && ($folder_prefix != '')) {
+ $start = substr_count($folder_prefix,$delimiter);
+ if (strrpos($folder_prefix, $delimiter) == (strlen($folder_prefix)-1)) {
+ $trail_del = true;
+ $mailboxes->mailboxname_full = substr($folder_prefix,0, (strlen($folder_prefix)-1));
+ } else {
+ $mailboxes->mailboxname_full = $folder_prefix;
+ $start++;
+ }
+ $mailboxes->mailboxname_sub = $mailboxes->mailboxname_full;
+ } else {
+ $start = 0;
+ }
+
+ $cnt = count($mbx_ary);
+ for ($i=0; $i < $cnt; $i++) {
+ if ($mbx_ary[$i]['mbx'] !='' ) {
+ $mbx = new mailboxes();
+ $mailbox = $mbx_ary[$i]['mbx'];
+
+ /*
+ sent subfolders messes up using existing code as subfolders
+ were marked, but the parents were ordered somewhere else in
+ the list, despite having "special folders at top" option set.
+ Need a better method than this.
+ */
+/*
+ if ($mailbox == 'INBOX') {
+ $mbx->is_special = true;
+ } elseif (stristr($trash_folder , $mailbox)) {
+ $mbx->is_special = true;
+ } elseif (stristr($sent_folder , $mailbox)) {
+ $mbx->is_special = true;
+ } elseif (stristr($draft_folder , $mailbox)) {
+ $mbx->is_special = true;