SM_PATH already defined
[squirrelmail.git] / src / left_main.php
index 5f2217959bb55645dd3bf933ba67621d72dd9900..c80d4a76263609bdf198b7430ce9eaf4cf881de9 100644 (file)
@@ -45,8 +45,19 @@ function formatMailboxName($imapConnection, $box_array) {
     if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
         $mailbox = $regs[2];
     }
-
-    list($unseen_string, $unseen) = create_unseen_string($real_box, $box_array, $imapConnection);
+    $unseen = 0;
+    $status = array();
+    if (($unseen_notify == 2 && $real_box == 'INBOX') ||
+        $unseen_notify == 3) {
+       $status = create_unseen_string($real_box, $box_array, $imapConnection, $unseen_type );
+       if ($status !== false) {
+           list($unseen_string, $unseen) = $status;
+       } else {
+           list($unseen_string, $unseen) = array(_("Not available"),'');
+       }
+    } else {
+       list($unseen_string, $unseen) = array('','');
+    }
     $special_color = ($use_special_folder_color && isSpecialMailbox($real_box));
 
     /* Start off with a blank line. */
@@ -56,9 +67,10 @@ function formatMailboxName($imapConnection, $box_array) {
     if ($unseen > 0) { $line .= '<B>'; }
 
     /* Create the link for this folder. */
-    $line .= '<a href="right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox='.
-             $mailboxURL.'" TARGET="right" STYLE="text-decoration:none">';
-
+    if ($status !== false) {
+       $line .= '<a href="right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox='.
+                $mailboxURL.'" TARGET="right" STYLE="text-decoration:none">';
+    } 
     if ($special_color) {
         $line .= "<font color=\"$color[11]\">";
     }
@@ -69,7 +81,9 @@ function formatMailboxName($imapConnection, $box_array) {
     }
     if ($special_color == TRUE)
         $line .= '</font>';
-    $line .= '</a>';
+    if ($status !== false) {
+       $line .= '</a>';
+    }
 
     /* If there are unseen message, close bolding. */
     if ($unseen > 0) { $line .= "</B>"; }
@@ -181,11 +195,11 @@ function create_collapse_link($boxnum) {
  * @return array[0] unseen message string (for display)
  * @return array[1] unseen message count
  */
-function create_unseen_string($boxName, $boxArray, $imapConnection) {
-    global $boxes, $unseen_type, $color;
+function create_unseen_string($boxName, $boxArray, $imapConnection, $unseen_type) {
+    global $boxes, $unseen_type, $color, $unseen_cum;
 
     /* Initialize the return value. */
-    $result = array();
+    $result = array(0,0);
 
     /* Initialize the counts for this folder. */
     $boxUnseenCount = 0;
@@ -194,14 +208,18 @@ function create_unseen_string($boxName, $boxArray, $imapConnection) {
     $totalMessageCount = 0;
 
     /* Collect the counts for this box alone. */
-    $boxUnseenCount = sqimap_unseen_messages($imapConnection, $boxName);
+    $status = sqimap_status_messages($imapConnection, $boxName);
+    $boxUnseenCount = $status['UNSEEN'];
+    if ($boxUnseenCount === false) {
+       return false;
+    }
     if ($unseen_type == 2) {
-        $boxMessageCount = sqimap_get_num_messages($imapConnection, $boxName);
+        $boxMessageCount = $status['MESSAGES'];
     }
 
     /* Initialize the total counts. */
 
-    if ($boxArray['collapse'] == SM_BOX_COLLAPSED) {
+    if ($boxArray['collapse'] == SM_BOX_COLLAPSED && $unseen_cum) {
         /* Collect the counts for this boxes subfolders. */
         $curBoxLength = strlen($boxName);
         $boxCount = count($boxes);
@@ -215,11 +233,11 @@ function create_unseen_string($boxName, $boxArray, $imapConnection) {
             if (($boxName != $boxes[$i]['unformatted'])
                    && (substr($boxes[$i]['unformatted'], 0, $curBoxLength) == $boxName)
                    && !in_array('noselect', $boxes[$i]['flags'])) {
-                $subUnseenCount = sqimap_unseen_messages($imapConnection, $boxes[$i]['unformatted']);
+               $status = sqimap_status_messages($imapConnection, $boxes[$i]['unformatted']);
+               $subUnseenCount = $status['UNSEEN'];
                 if ($unseen_type == 2) {
-                    $subMessageCount = sqimap_get_num_messages($imapConnection, $boxes[$i]['unformatted']);
+                    $subMessageCount = $status['MESSAGES'];;
                 }
-
                 /* Add the counts for this subfolder to the total. */
                 $totalUnseenCount += $subUnseenCount;
                 $totalMessageCount += $subMessageCount;
@@ -312,7 +330,8 @@ function listBoxes ($boxes, $j=0 ) {
 
        if (($move_to_trash) && ($mailbox == $trash_folder)) {
            if (! isset($numMessages)) {
-               $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
+               $status = sqimap_status_messages($imapConnection, $mailbox);
+               $numMessages = $status['MESSAGES'];
            }
 
            if ($numMessages > 0) {
@@ -489,7 +508,17 @@ function ListAdvancedBoxes ($boxes, $mbx, $j='ID.0000' ) {
 
 /* -------------------- MAIN ------------------------ */
 
-global $delimiter, $default_folder_prefix, $left_size;
+$key = $_COOKIE['key'];
+$onetimepad = $_SESSION['onetimepad'];
+$username = $_SESSION['username'];
+$delimiter = $_SESSION['delimiter'];
+
+if (isset($_GET['fold'])) {
+    $fold = $_GET['fold'];
+}
+if (isset($_GET['unfold'])) {
+    $unfold = $_GET['unfold'];
+}
 
 // open a connection on the imap port (143)
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
@@ -784,7 +813,7 @@ if ($auto_create_special && !isset($auto_create_done)) {
 
     /* Let the world know that autocreation is complete! Hurrah! */
     $auto_create_done = TRUE;
-    session_register('auto_create_done');
+    sqsession_register($auto_create_done, 'auto_create_done');
 }
 
 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
@@ -800,7 +829,7 @@ if ($advanced_tree) {
    echo '<div ID="leftframe"><br><br>';
 }
 
-echo "\n\n" . html_tag( 'table', '', '', '', 'border="0" cellspacing="0" cellpadding="0" width="100%"' ) . 
+echo "\n\n" . html_tag( 'table', '', 'left', '', 'border="0" cellspacing="0" cellpadding="0" width="99%"' ) . 
     html_tag( 'tr' ) . 
     html_tag( 'td', '', 'left' ) . 
     '<center><font size="4"><b>'. _("Folders") . "</b><br></font>\n\n";
@@ -914,7 +943,7 @@ for ($i = 0; $i < count($boxes); $i++) {
 } else {  /* expiremental code */ 
     $boxes = sqimap_mailbox_tree($imapConnection);
     if (isset($advanced_tree) && $advanced_tree) {
-       echo '<FORM name=collapse action="left_main.php" METHOD=POST' .
+       echo '<FORM name=collapse action="left_main.php" METHOD=POST ' .
             'ENCTYPE="multipart/form-data"'."\n";
        echo '<small><button type="submit" class="button" onmouseover="buttonover(this,true)" onmouseout="buttonover(this,false)" onmousedown="buttonclick(this,true)" onmouseup="buttonclick(this,false)">'. _("Save folder tree") .'</button><br><br>';
        echo '<DIV ID=mailboxes CLASS=mailboxes>'."\n\n";