-function sqimap_mailbox_tree($imap_stream) {
- global $default_folder_prefix, $data_dir, $username, $list_special_folders_first,
- $folder_prefix, $delimiter, $trash_folder, $move_to_trash,
- $imap_server_type, $show_only_subscribed_folders;
-
- // TODO: implement mailbox tree caching. maybe store object in session?
-
- $noselect = false;
- $noinferiors = false;
-
- require_once(SM_PATH . 'include/load_prefs.php');
-
- if ($show_only_subscribed_folders) {
- $lsub_cmd = 'LSUB';
- } else {
- $lsub_cmd = 'LIST';
- }
-
- /* LSUB array */
- $lsub_ary = sqimap_run_command ($imap_stream, "$lsub_cmd \"$folder_prefix\" \"*\"",
- true, $response, $message);
- $lsub_ary = compact_mailboxes_response($lsub_ary);
-
- /* Check to see if we have an INBOX */
- $has_inbox = false;
-
- for ($i = 0, $cnt = count($lsub_ary); $i < $cnt; $i++) {
- if (preg_match("/^\*\s+$lsub_cmd.*\s\"?INBOX\"?\s*$/i",$lsub_ary[$i])) {
- $lsub_ary[$i] = strtoupper($lsub_ary[$i]);
- // in case of an unsubscribed inbox an imap server can
- // return the inbox in the lsub results with a \NoSelect
- // flag.
- if (!preg_match("/\*\s+$lsub_cmd\s+\(.*\\\\NoSelect.*\).*/i",$lsub_ary[$i])) {
- $has_inbox = true;
- } else {
- // remove the result and request it again with a list
- // response at a later stage.
- unset($lsub_ary[$i]);
- // re-index the array otherwise the addition of the LIST
- // response will fail in PHP 4.1.2 and probably other older versions
- $lsub_ary = array_values($lsub_ary);
- }
- break;
- }
- }
-
- if ($has_inbox == false) {
- // do a list request for inbox because we should always show
- // inbox even if the user isn't subscribed to it.
- $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" "INBOX"',
- true, $response, $message);
- $inbox_ary = compact_mailboxes_response($inbox_ary);
- if (count($inbox_ary)) {
- $lsub_ary[] = $inbox_ary[0];
- }
- }
-
- /*
- * Section about removing the last element was removed
- * We don't return "* OK" anymore from sqimap_read_data
- */