Fixes some bugs in preferences
[squirrelmail.git] / src / left_main.php
index 7a2d670c4d905948f49b3c1c7be3c3a2c06a3ab5..655895448b9ec9216046a69752a01cece893bf01 100644 (file)
@@ -1,6 +1,6 @@
 <?
    /**
-    **  left_main.php3
+    **  left_main.php
     **
     **  This is the code for the left bar.  The left bar shows the folders
     **  available, and has cookie information.
    }
 ?>
 <HTML>
-<HEAD>
-   <SCRIPT LANGUAGE="JavaScript">
-      function DeleteCookie (name) {
-         var exp = new Date();  
-         exp.setTime (exp.getTime() - 1);  
-         // This cookie is history  
-         var cval = GetCookie (name);  
-         document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
+<?
+   include("../config/config.php");
+   include("../functions/array.php");
+   include("../functions/strings.php");
+   include("../functions/imap.php");
+   include("../functions/mailbox.php");
+
+   function formatMailboxName($imapConnection, $mailbox, $delimeter, $color) {
+      require ("../config/config.php");
+
+      $mailboxURL = urlencode($mailbox);
+      selectMailbox($imapConnection, $mailbox, $numNessages);
+      $unseen = unseenMessages($imapConnection, $numUnseen);
+
+      echo "<NOBR>";
+      if ($unseen)
+         $line .= "<B>";
+
+      $special_color = false;
+      for ($i = 0; $i < count($special_folders); $i++) {
+         if (($special_folders[$i] == $mailbox) && ($use_special_folder_color == true))
+            $special_color = true;
       }
 
-      function unSetCookies() {
-         DeleteCookie('username');
-         DeleteCookie('key');
-         DeleteCookie('logged_in');
-         alert(document.cookie);
+      if ($special_color == true) {
+         $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\"><FONT FACE=\"Arial,Helvetica\"  COLOR=\"$color[11]\">";
+         $line .= readShortMailboxName($mailbox, $delimeter);
+         $line .= "</font></a>";
+      } else {
+         $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\"><FONT FACE=\"Arial,Helvetica\">";
+         $line .= readShortMailboxName($mailbox, $delimeter);
+         $line .= "</font></a>";
       }
-   </SCRIPT>
-</HEAD>
-<BODY BGCOLOR=A0B8C8 TEXT="#000000" LINK="#0000EE" VLINK="#0000EE" ALINK="#0000EE" onUnLoad="unSetCookies()">
-<FONT FACE="Arial,Helvetica">
-<?
-   include("../config/config.php3");
-   include("../functions/strings.php3");
-   include("../functions/imap.php3");
-
-   // *****************************************
-   //    Parse the incoming mailbox name and return a string that is the FOLDER.MAILBOX
-   // *****************************************
-   function findMailboxName($mailbox) {
-      // start at -2 so that we skip the initial quote at the end of the mailbox name
-      $i = -2;
-      $char = substr($mailbox, $i, 1);
-      while ($char != "\"") {
-         $i--;
-         $temp .= $char;
-         $char = substr($mailbox, $i, 1);
+
+      if ($unseen)
+         $line .= "</B>";
+
+      if ($numUnseen > 0) {
+         $line .= "&nbsp;<FONT FACE=\"Arial,Helvetica\" SIZE=2>($numUnseen)</FONT>";
+      }
+
+      if (($move_to_trash == true) && (trim($mailbox) == $trash_folder)) {
+         $urlMailbox = urlencode($mailbox);
+         $line .= "<FONT FACE=\"Arial,Helvetica\" SIZE=2>";
+         $line .= "&nbsp;&nbsp;&nbsp;&nbsp;(<B><A HREF=\"empty_trash.php?numMessages=$numMessages&mailbox=$urlMailbox\" TARGET=right style=\"text-decoration:none\">empty</A></B>)";
+         $line .= "</FONT></a>\n";
       }
-      return strrev($temp);
+
+      echo "</NOBR>";
+      return $line;
    }
 
    // open a connection on the imap port (143)
-   $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString);
-   if (!$imapConnection) {
-      echo "Error connecting to IMAP Server.<br>";
-      echo "$errorNumber : $errorString<br>";
-      exit;
-   }
-   $serverInfo = fgets($imapConnection, 256);
-
-   fputs($imapConnection, "1 login $username $key\n");
-   $read = fgets($imapConnection, 1024);
-
-   fputs($imapConnection, "1 list \"\" *\n");
-   $str = imapReadData($imapConnection);
-
-   echo "<FONT FACE=\"Arial,Helvetica\"><B>";
-   echo "<CENTER>$org_name</B><BR>";
-   echo "Folders</CENTER>";
-   echo "</B><BR></FONT>";
-   echo "<code><FONT FACE=\"Arial,Helvetica\">\n";
-   for ($i = 0;$i < count($str); $i++) {
-      $mailbox = Chop($str[$i]);
-      // find the quote at the begining of the mailbox name.
-      //    i subtract 1 from the strlen so it doesn't find the quote at the end of the mailbox name.
-      $mailbox = findMailboxName($mailbox);
-      $periodCount = countCharInString($mailbox, ".");
-      
+   $imapConnection = loginToImapServer($username, $key, $imapServerAddress, 10); // the 10 is to hide the output
+
+   /** If it was a successful login, lets load their preferences **/
+   include("../src/load_prefs.php");
+   echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">";
+   echo "<FONT FACE=\"Arial,Helvetica\">";
+
+   getFolderList($imapConnection, $boxes);
+
+   echo "<FONT FACE=\"Arial,Helvetica\" SIZE=4><B><CENTER>";
+   echo "Folders</B><BR></FONT>";
+
+   echo "<FONT FACE=\"Arial,Helvetica\" SIZE=2>(<A HREF=\"../src/left_main.php\" TARGET=left>refresh folder list</A>)</FONT></CENTER><BR>";
+   echo "<FONT FACE=\"Arial,Helvetica\">\n";
+   $delimeter = findMailboxDelimeter($imapConnection);
+   for ($i = 0;$i < count($boxes); $i++) {
+      $mailbox = $boxes[$i]["UNFORMATTED"];
+      $boxFlags = getMailboxFlags($boxes[$i]["RAW"]);
+
+      $boxCount = countCharInString($mailbox, $delimeter);
+
+      $line = "";
       // indent the correct number of spaces.
-      for ($j = 0;$j < $periodCount;$j++)
-         echo "&nbsp;&nbsp;";
-      
-      $mailboxURL = urlencode($mailbox);
-      echo "<a href=\"right_main.php3?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\"><FONT FACE=\"Arial,Helvetica\">";
-      echo readShortMailboxName($mailbox, ".");
-      echo "</FONT></a><br>\n";
+      for ($j = 0;$j < $boxCount;$j++)
+         $line .= "&nbsp;&nbsp;";
+
+      if (trim($boxFlags[0]) != "") {
+         $noselect = false;
+         for ($h = 0; $h < count($boxFlags); $h++) {
+            if (strtolower($boxFlags[$h]) == "noselect")
+               $noselect = true;
+         }
+
+         if ($noselect == true) {
+            $line .= "<FONT COLOR=\"$color[10]\" FACE=\"Arial,Helvetica\">";
+            $line .= readShortMailboxName($mailbox, $delimeter);
+            $line .= "</FONT><FONT FACE=\"Arial,Helvetica\">";
+         } else {
+            $line .= formatMailboxName($imapConnection, $mailbox, $delimeter, $color);
+         }
+      } else {
+         $line .= formatMailboxName($imapConnection, $mailbox, $delimeter, $color);
+      }
+      echo "$line<BR>";
    }
-   echo "</code></FONT>";
+
+   echo "</FONT>";
 
    fclose($imapConnection);