Code cleaning
[squirrelmail.git] / functions / imap_mailbox.php
index b3ff5a469b340f17d728656d947b9a62826bf168..7fc6889d4ae33551bd2d2af079a0a6a8dede6c5c 100755 (executable)
@@ -43,14 +43,16 @@ function isBoxBelow( $box2, $box1 ) {
 function isSpecialMailbox( $box ) {
 
     global $trash_folder, $sent_folder, $draft_folder,
-           $move_to_trash, $move_to_sent, $save_as_draft,
-           $delimiter, $folder_prefix, $imap_server_type;
+           $move_to_trash, $move_to_sent, $save_as_draft;
 
     $ret = ( (strtolower($box) == 'inbox') ||
              ( $move_to_trash && isBoxBelow( $box, $trash_folder ) ) ||
              ( $move_to_sent && isBoxBelow( $box, $sent_folder )) ||
-             ($box == $draft_folder &&
-              $save_as_draft) );
+             ($save_as_draft && $box == $draft_folder ) );
+
+    if ( !$ret ) {
+        $ret = do_hook_function( 'special_mailbox', $box );
+    }
 
     return( $ret );
 
@@ -83,14 +85,14 @@ function sqimap_mailbox_exists ($imap_stream, $mailbox)
  **  Selects a mailbox
  ******************************************************************************/
 function sqimap_mailbox_select ($imap_stream, $mailbox,
-                                $hide=TRUE, $recent=false)
+                                $hide=TRUE, $recent=false, $extrainfo=false)
 {
     global $auto_expunge;
-    
+
     if ( $mailbox == 'None' ) {
         return;
     }
-    
+
     $read = sqimap_run_command($imap_stream, "SELECT \"$mailbox\"",
                                TRUE, $response, $message);
     if ($recent) {
@@ -100,17 +102,42 @@ function sqimap_mailbox_select ($imap_stream, $mailbox,
             }
         }
         return $r[1];
-    }
-    if ($auto_expunge) {
-        $tmp = sqimap_run_command($imap_stream, 'EXPUNGE',
+    } else {
+        if ($auto_expunge) {
+            $tmp = sqimap_run_command($imap_stream, 'EXPUNGE',
                                   false, $a, $b);
+        }
+        if (isset( $extrainfo ) && $extrainfo) {
+            $result = array();
+            for ($i=0; $i<count($read); $i++) {
+                if (preg_match("/PERMANENTFLAGS(.*)/i",$read[$i], $regs)) {
+                    $regs[1]=trim(preg_replace (  array ("/\(/","/\)/","/\]/") ,'', $regs[1])) ;
+                    $result['PERMANENTFLAGS'] = $regs[1];
+                }
+                else if (preg_match("/FLAGS(.*)/i",$read[$i], $regs)) {
+                    $regs[1]=trim(preg_replace (  array ("/\(/","/\)/") ,'', $regs[1])) ;
+                    $result["FLAGS"] = $regs[1];
+                }
+                else if (preg_match("/(.*)EXISTS/i",$read[$i], $regs)) {
+                    $result['EXISTS']=trim($regs[1]);
+                }
+                else if (preg_match("/(.*)RECENT/i",$read[$i], $regs)) {
+                    $result['RECENT']=trim($regs[1]);
+                }
+                else if (preg_match("/\[UNSEEN(.*)\]/i",$read[$i], $regs)) {
+                    $result['UNSEEN']=trim($regs[1]);
+                }
+
+            }
+            return( $result );
+        }
     }
 }
 
 
 
 /******************************************************************************
- **  Creates a folder 
+ **  Creates a folder
  ******************************************************************************/
 function sqimap_mailbox_create ($imap_stream, $mailbox, $type)
 {
@@ -120,7 +147,7 @@ function sqimap_mailbox_create ($imap_stream, $mailbox, $type)
     }
     $read_ary = sqimap_run_command($imap_stream, "CREATE \"$mailbox\"",
                                    TRUE, $response, $message);
-    
+
     sqimap_subscribe ($imap_stream, $mailbox);
 }
 
@@ -358,13 +385,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');
@@ -496,6 +523,7 @@ function sqimap_mailbox_list ($imap_stream) {
     }
 
     return( $boxesnew );
+
 }
 
 /*
@@ -506,9 +534,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 );
@@ -530,7 +556,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]);