Create $aCriteria to prevent a notice later on if there is nothing in it
[squirrelmail.git] / functions / imap_mailbox.php
index 827a83dc1b723bcd58d3040fa9ac87dab452c800..a5e50c7f0402f5e115cd7cbd67259461a8c7437e 100755 (executable)
@@ -3,11 +3,10 @@
 /**
  * imap_mailbox.php
  *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
  * This implements all functions that manipulate mailboxes
  *
+ * @copyright © 1999-2005 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  * @subpackage imap
@@ -431,16 +430,20 @@ function sqimap_unsubscribe ($imap_stream, $mailbox) {
 function sqimap_mailbox_delete ($imap_stream, $mailbox) {
     global $data_dir, $username;
     sqimap_unsubscribe ($imap_stream, $mailbox);
-    $read_ary = sqimap_run_command($imap_stream, 'DELETE ' .
-                                   sqimap_encode_mailbox_name($mailbox),
-                                   true, $response, $message);
-    if ($response !== 'OK') {
-        // subscribe again
-        sqimap_subscribe ($imap_stream, $mailbox);
-    } else {
-        do_hook_function('rename_or_delete_folder', $args = array($mailbox, 'delete', ''));
-        removePref($data_dir, $username, "thread_$mailbox");
-        removePref($data_dir, $username, "collapse_folder_$mailbox");
+
+    if (sqimap_mailbox_exists($imap_stream, $mailbox)) {
+
+        $read_ary = sqimap_run_command($imap_stream, 'DELETE ' .
+                                       sqimap_encode_mailbox_name($mailbox),
+                                       true, $response, $message);
+        if ($response !== 'OK') {
+            // subscribe again
+            sqimap_subscribe ($imap_stream, $mailbox);
+        } else {
+            do_hook_function('rename_or_delete_folder', $args = array($mailbox, 'delete', ''));
+            removePref($data_dir, $username, "thread_$mailbox");
+            removePref($data_dir, $username, "collapse_folder_$mailbox");
+        }
     }
 }
 
@@ -741,7 +744,7 @@ function sqimap_mailbox_list($imap_stream, $force=false) {
            * in other words, we cannot rely on it.
          */
         $sorted_list_ary = array();
//       if (!$listsubscribed) {
       if (!$listsubscribed && $show_only_subscribed_folders) {
           for ($i=0; $i < count($sorted_lsub_ary); $i++) {
             if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
                 $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i])-1);
@@ -761,7 +764,9 @@ function sqimap_mailbox_list($imap_stream, $force=false) {
                 $sorted_list_ary[$i] = '';
             }
           }
- //       }
+        } else {
+          $sorted_list_ary = $sorted_lsub_ary;
+        }
         /*
          * Just in case they're not subscribed to their inbox,
          * we'll get it for them anyway
@@ -1102,6 +1107,7 @@ function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) {
  * @since 1.5.0
  */
 function sqimap_utf7_decode_mbx_tree(&$mbx_tree) {
+
    if (strtoupper($mbx_tree->mailboxname_full) == 'INBOX')
        $mbx_tree->mailboxname_sub = _("INBOX");
    else
@@ -1109,7 +1115,7 @@ function sqimap_utf7_decode_mbx_tree(&$mbx_tree) {
    if ($mbx_tree->mbxs) {
       $iCnt = count($mbx_tree->mbxs);
       for ($i=0;$i<$iCnt;++$i) {
-          $mbxs_tree->mbxs[$i] = sqimap_utf7_decode_mbx_tree($mbx_tree->mbxs[$i]);
+            sqimap_utf7_decode_mbx_tree($mbx_tree->mbxs[$i]);
       }
    }
 }
@@ -1207,4 +1213,46 @@ function sqimap_get_status_mbx_tree($imap_stream,&$mbx_tree) {
     }
 }
 
-?>
\ No newline at end of file
+/**
+ * Checks if folder is noselect (can't store messages)
+ *
+ * Function does not check if folder subscribed.
+ * @param stream $oImapStream imap connection resource
+ * @param string $sImapFolder imap folder name
+ * @param object $oBoxes mailboxes class object.
+ * @return boolean true, when folder has noselect flag. false in any other case.
+ * @since 1.5.1
+ */
+function sqimap_mailbox_is_noselect($oImapStream,$sImapFolder,&$oBoxes) {
+    // build mailbox object if it is not available
+    if (! is_object($oBoxes)) $oBoxes=sqimap_mailbox_list($oImapStream);
+    foreach($oBoxes as $box) {
+        if ($box['unformatted']==$sImapFolder) {
+            return (bool) check_is_noselect($box['raw']);
+        }
+    }
+    return false;
+}
+
+/**
+ * Checks if folder is noinferiors (can't store other folders)
+ *
+ * Function does not check if folder subscribed.
+ * @param stream $oImapStream imap connection resource
+ * @param string $sImapFolder imap folder name
+ * @param object $oBoxes mailboxes class object.
+ * @return boolean true, when folder has noinferiors flag. false in any other case.
+ * @since 1.5.1
+ */
+function sqimap_mailbox_is_noinferiors($oImapStream,$sImapFolder,&$oBoxes) {
+    // build mailbox object if it is not available
+    if (! is_object($oBoxes)) $oBoxes=sqimap_mailbox_list($oImapStream);
+    foreach($oBoxes as $box) {
+        if ($box['unformatted']==$sImapFolder) {
+            return (bool) check_is_noinferiors($box['raw']);
+        }
+    }
+    return false;
+}
+
+?>